Here's an example using the
Type.GetGenericArguments()[
^] method:
public class Example
{
public List<int?> Target { get; set; }
}
Type type = typeof(Example).GetProperty("Target").PropertyType;
Type generic = type.GetGenericArguments().First();
Console.WriteLine($"Type {type} has generic argument {generic}");
The method returns an array so you can either use
First()
to select the first element, or use the standard array indexer
[0]