Get type of class in a static method

Hi

I have a base class X and a few that inherits from it.

I have a static function in the base class and I need to find out what is the type of the class I currently in.

I can't use GetType or typeof because it is static.

Could it be with generics

Thanks

Avi



Answer this question

Get type of class in a static method

  • rulertbca

    class Class1
    {
    static void staticmember()
    {
    Type t = typeof(Class1);
    }
    }



  • James Johnston

    The static member cannot possibly tell that it got inherited at compile time. It has no "this" to do it at runtime either. All you can do is override the method in the derived class...



  • JIM.H.

    nobugz, lets say I have Class2 that inherits from Class1. Now what would you do

    The thing I want is something like this : Type t = typeof(the class i am in);

    Any way, I found out this way :

    class A<T>

    {

    public static void Type()

    {

    Console.WriteLine(typeof(T).ToString());

    }

    }

    class B : A<B>

    {

    }


  • Get type of class in a static method