In C# how do you use reflection to get variables that doesn’t have getters/setters? For example the getValue method below will work for d2, but not d1.
public class Foo {
public String d1;
public String d2 { get; set; }
public object getValue(String propertyName){
return this.GetType().GetProperty(propertyName).GetValue(this, null);
}
}
d1is not a property. It is a field. Use the reflection methods for Fields instead.