Manipulate method functionality call

Posted by danrichardson on Stack Overflow See other posts from Stack Overflow or by danrichardson
Published on 2010-06-08T15:29:42Z Indexed on 2010/06/08 15:32 UTC
Read the original article Hit count: 158

Filed under:
|
|
|

Hello, is it possibly in c# to have some sort of base class functionality which is manipulated slightly based on the class. For instance say i have the following code (which will quite obviously not compile it's meant to only be for demonstrative purposes)

class BaseFunctionality
{
    public virtual bool adminCall
    public static string MethodName(int id, string parameter)
    { 
        if (adminCall)
            return dbcall.Execute();
        else
            return dbcall.ExecuteMe();
    }
}
class Admin : BaseFunctionality
{
    override bool adminCall = true;
}
class Front : BaseFunctionality
{
    override bool adminCall = false;
}

Now what i would like to be able to do is;

string AdminCall = Admin.MethodName(1, "foo");
string FrontCall = Front.MethodName(2, "bar");

Is their any way to do something like this? I'm trying to do everything with static methods so i do not have to instantiate classes all the time, and have nice clean code which is only being manipulated in one place.

The idea behind this is so that there is minimal code repeating and makes things easier to expand on, so for instance another class could implement the BaseFunctionality later on.

Thanks
Dan

© Stack Overflow or respective owner

Related posts about c#

Related posts about classes