C# - Complete return from base method

c#, derived, inheritance, methods, radix

Solution

Do not use it with `void` returned type, but can do, say `bool`

public class Base
{
    public virtual bool Action()
    {
       ..
       return boolean-value.
    }
}

public class Child : Base
{
    public override bool Action()
    {
       if(!base.Action()) 
         return false;

       ....
       return boolean-value;
    }
}

Or, if this is a exceptional situation, raise an exception, like others suggest.

Problem

I have a virtual base method `void Action()` that is overridden in a derived class. The first step in Action is to call `base.Action()`. If a situation occurs in the base method I do not want the rest of the derived method to be processed. I want to know is there a keyword or design pattern that will allow me to exit the derived method from the base method. Currently I am looking at changing the void to bool and using that as a flow control, but I was wondering if there are any other design patterns I might be able to use.

Original source