c# class design - what can I use instead of "static abstract"?

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2010-05-24T19:53:10Z Indexed on 2010/05/24 20:01 UTC
Read the original article Hit count: 172

Filed under:
|

I want to do the following

public abstract class MyAbstractClass
{
    public static abstract int MagicId
    {
        get;
    }

    public static void DoSomeMagic()
    {
        // Need to get the MagicId value defined in the concrete implementation
    }
}

public class MyConcreteClass : MyAbstractClass
{
    public static override int MagicId
    {
        get { return 123; }
    }
}

However I can't because you can't have static abstract members.

I understand why I can't do this - any recommendations for a design that will achieve much the same result?

(For clarity - what I am trying to do is provide a library with an abstract base class but the concrete versions MUST implement a few properties/methods themselves and yes, there are good reasons for keeping it static.)

© Stack Overflow or respective owner

Related posts about c#

Related posts about design-patterns