inheritance - C# calling parent property while the child property is being called -


i wanna see if there anyway when child property method being called, call parent property well. note child generated code generator edmx. can't change except adding partial class child class. (it might trouble change generator.)

the situation having : have class "myclass" automatically generated database. can't change on except adding partial class or change code generator.

now, need "do something" whenever property name being called. thinking if can put parent there , make call parent "something" when child property "name" being called.

what want :

public class classbase {     public string name      {                   {              callmethod();             return name;         }     } }  public class myclass : classbase  {     public string name { get; set; } }   myclass myclass = new myclass(); myclass.name; < -- call parent well. 

is there anyway it?

thanks in advance

not related since you're not strictly using automatic properties in classbase, should create private string variable name. _name or whatever internal coding standards dictate.

public class classbase {   private string _name;   public virtual string name    {           {        callmethod();       return _name;     }     set     {       _name = value;     }   } }   public class myclass : classbase  {   //pretty pointless since you're not doing myclass.name.   public new string name   {         {       return base.name;     }     set     {       base.name = value;     } }   myclass myclass = new myclass(); myclass.name; <-- call parent well. 

Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -