mercredi 28 décembre 2016

C# call method before override method

Good day, I have a base class with a virtual method that needs to be overridden per implementation, but I would like to call the base method first before overriding. Is there a way to accomplish this without having to actually call the method.

public class Base
{
   public virtual void Method()
   {
      //doing some stuff here 
   }
}

public class Parent : Base
{
  public override void Method()
  {
     base.Method() //need to be called ALWAYS
     //then I do my thing 
  } 
}

I cannot always rely that the base.Method() will be called in the override, so I would like to enforce it somehow. This might be a design pattern of some kind, any approach to accomplish the result will do.

Aucun commentaire:

Enregistrer un commentaire