I want to get derived type from static method.
I want to do something like this
void foo()
{
this.getType();
}
but in static method
I know that
MethodBase.GetCurrentMethod().DeclaringType
returns base type, but i need derived.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you mean you have something like this
and want
MyDerivedClass.DoSomething();to print"MyDerivedClass", then the answer is:There is no solution to your problem. Static methods are not inherited like instance methods. You can refer to
DoSomethingusingMyBaseClass.DoSomethingorMyDerivedClass.DoSomething, but both are compiled as calls toMyBaseClass.DoSomething. It is not possible to find out which was used in the source code to make the call.