Check if a class is derived from a generic class

前端 未结 16 1361
太阳男子
太阳男子 2020-11-22 09:57

I have a generic class in my project with derived classes.

public class GenericClass : GenericInterface
{
}

public class Test : GenericCla         


        
16条回答
  •  有刺的猬
    2020-11-22 10:06

    Type _type = myclass.GetType();
    PropertyInfo[] _propertyInfos = _type.GetProperties();
    Boolean _test = _propertyInfos[0].PropertyType.GetGenericTypeDefinition() 
    == typeof(List<>);
    

提交回复
热议问题