Jared

Jared

  • NA
  • 1
  • 0

Type for current class?

Apr 12 2008 7:33 PM
I think it's a long shot but I figure I'd ask if this was possible just in case.

Does anyone know of some way to specify the current class type similar to the way you would use generics? Hard to word, example:

class Example
{
    public Example DefaultExample;
}

only instead of stating the class explicitly, I would like some implicit way to do it such as:

class Example
{
    public <T> DefaultExample;
}

So that child classes would automatically have a DefaultExample member of their own class type:

class ExampleChild : Example
{
    void DoChildStuff()
    {
        Default.DoChildStuff()
    }
}

i can sort of achieve this by doing the following:

    class ExampleBase<Type>
    {
        public Type DefaultExample;
    }

    class ExampleChild : ExampleBase<ExampleChild>
    {
    }

    class ExampleChildChild : ???
    {
    }

but obviously the inheritance breaks after the first level

Any ideas or is this just not feasible?

Answers (1)