I have a class A with a static method, and a derived class B. You can call Foo(), declared in A, on both A and B:
public class A
{
public static void Foo()
{
// How to get typeof(B) here if Foo called by using class B?
}
}
public class B : A
{
}
...
static class Program
{
static void Main()
{
B.Foo();
}
}
Now inside Foo(), how can I find out on which type Foo() was called?
I can't use keyword this, because I do not create any objects here. I have tried already:
MethodBase.GetCurrentMethod().DeclaringType
and
MethodBase.GetCurrentMethod().ReflectedType
but they both return me the typeof(A), while I need to get the typeof(B).