在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,他們不是屬性。他們是田野。他們不是一回事。 –