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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -