c# reflection list of type code example
Example 1: c# get property type of list
var obj = new PropClassDemo();
foreach (PropertyInfo prop in obj.GetType().GetProperties())
{
if(prop.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(prop.PropertyType))
{
Console.Writeline("This prop's type is Ienumerable");
}
}
Example 2: c# get list object type of generic list
Type type = pi.PropertyType;
if(type.IsGenericType && type.GetGenericTypeDefinition()
== typeof(List<>))
{
Type itemType = type.GetGenericArguments()[0];
}