c# - Calling subclass method after calling superclass method -


this question has answer here:

ultimately, call subclass method after calling superclass method. have code this:

public class superclass {     protected wrapperclass<t> getwrapperclass<t>()     {         return new wrapperclass(somestuff).wrap<t>();     }      public superclass commonmethod1()     {         //         return this;     }      public superclass commonmethod2()     {         // else         return this;     }      // many commonmethods }  public class subclass : superclass {     public wrapperclass<someclass> optionallastmethod1()     {         return base.getwrapperclass<someclass>();     }      public wrapperclass<someotherclass> optionallastmethod2()     {         return base.getwrapperclass<someotherclass>();     } } 

i this:

new subclass()     .commonmethod1()     .commonmethod2()      // returns superclass     .optionallastmethod1();  // this. 

i avoid casting superclass subclass this:

var subclass = ((subclass)new subclass().commonmethod1().commonmethod2()).lastmethodtocall(); 

the important point here ease of use, not ease of implementation. input appreciated.

solved doing this. - removed irrelevant code.

public class superclass<s> s : superclass<s> {     public s commonmethod1()     {         //         return (s) this;     }      public s commonmethod2()     {         // else         return (s) this;     }      // many commonmethods }  public class subclass : superclass<subclass> {     public wrapperclass<someclass> optionallastmethod1()     {         return base.getwrapperclass<someclass>();     }      public wrapperclass<someotherclass> optionallastmethod2()     {         return base.getwrapperclass<someotherclass>();     } } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -