c# - How to set derived class property from base class -
let me begin saying aware of dangers of doing , understand 100% it's "bad idea"... but...
how can set derived class property base class?
public class foo { public void setsomevalue(int someparam) { var propertyinfo = this.gettype() .getproperties(bindingflags.instance | bindingflags.public) .where(t => t.name == "somevalue") .first(); propertyinfo.setvalue(null, someparam); // <-- shouldn't null } } public class bar : foo { public int somevalue { get; set; } }
how can hold of property value in order call setvalue?
edit:
this easy. doh.
propertyinfo.setvalue(this, someparam);
propertyinfo.setvalue(this, someparam);
Comments
Post a Comment