我想知道如何使用反射机制在以下情况下属性:C#反射找到哪种类型的继承一些其他类型的
public class A { }
public class B { }
public class ListA : ICollection<A> { }
public class ListB : ICollection<B> { }
public class Container
{
public ListA LA { get; set; }
public ListB LB { get; set; }
}
那么我想找到一个属性,该属性类型继承类型ICollection<B>
var container = new Container();
var found = container.GetType().GetProperties().FirstOrDefault(x => x.PropertyType == typeof(ICollection<B>));
并且当然found
变量为空,那么如何更深入地反思?
我是否正确理解第一种方法应该与类一起工作呢? –
@SamvelPetrosov是的。 –