在C#中,如何使用反射来获取没有getter/setters的变量?例如,下面的getValue方法适用于d2,但不适用于d1。C#获取反射域
public class Foo {
public String d1;
public String d2 { get; set; }
public object getValue(String propertyName){
return this.GetType().GetProperty(propertyName).GetValue(this, null);
}
}
如果他们没有getter或setters,他们不是属性。他们是田野。他们不是一回事。 –