谁能看到我在下面做错了什么?该类型具有服务方法试图访问的公共属性,那么为什么它没有被反射拾取呢?
Public class SomeClass
{
private YetAnotherClass yetAnotherClass;
public SomeClass(SomeOtherClass otherclass)
{
this.yetAnotherClass = otherclass.SomeProperty;
}
public YetAnotherClass SomeProperty
{
get { return this.yetAnotherClass; }
}
}
Public class ServiceClass
{
public void DoSomething(SomeClass someclass)
{
Type type = someclass.GetType();
FieldInfo[] fieldsinfo = type.GetFields(BindingFlags.Public | BindingFlags.Instance); // returns empty collection
FieldInfo fieldinfo = type.GetField("SomeProperty"); // returns null reference exception
}
}
干杯
斯图尔特