c# - How to change value of DefaultValue attribute in subclass -
i'm not sure if want possible, figured i'd ask.
i have abstract base class has property that's decorated defaultvalue attribute, so:
public abstract mybaseclass {      [defaultvalue( "some value" )]     public string stringproperty {          { return istringproperty; }         set { istringproperty = value;     }     protected string istringproperty = "some value";      // other code here }   i want derive child class mybaseclass, want value in defaultvalue attribute, default value of property, different.  end, have added default constructor child class, follows:
public class mychildclass : mybaseclass {      // type specific properties & fields here      public mychildclass()         : base() {         istringproperty = "new value";     }      // other code here }   how change value of defaultvalue attribute in derived class it's "new value"?
if property virtual override , apply defaultvalue it.
[defaultvalue( "new value" )] public override string stringproperty {      { return istringproperty; }     set { istringproperty = value;} }   if not, need shadow property new keyword , apply new defaultvalue
[defaultvalue( "new value" )] public new string stringproperty  {      { return istringproperty; }     set { istringproperty = value;} }   in both cases don't need provide new implementation. delegate call base.stringproperty;
Comments
Post a Comment