I think you need something like this script:
void Main() { Base.StaticMethod(); // should return "Base" Derived.StaticMethod(); // should return "Derived" } class Base { public static void StaticMethod() { Console.WriteLine(MethodBase.GetCurrentMethod().DeclaringType.Name); } } class Derived: Base { }
This code, however, will return
Base Base
This is because the call to the static method is allowed at compile time as a call to the base class, which actually defines it, even if it was called from a derived class. Lines
Base.StaticMethod(); Derived.StaticMethod();
generates the following IL:
IL_0001: call Base.StaticMethod IL_0006: nop IL_0007: call Base.StaticMethod
In a word, this is impossible.
Sweko source share