Let's say I have this line:
MethodBody getTypeMethod = typeof(object).GetMethod("GetType").GetMethodBody();
// getTypeMethod is null
Why is getTypeMethod
null? How can I get the MethodBody
of the GetType()
method?
Let's say I have this line:
MethodBody getTypeMethod = typeof(object).GetMethod("GetType").GetMethodBody();
// getTypeMethod is null
Why is getTypeMethod
null? How can I get the MethodBody
of the GetType()
method?
You got to the answer yourself, but just to confirm, Object.GetType()
is an external method and external methods does not have a method body specified.
From C# specs 10.6.7
When a method declaration includes an extern modifier, that method is said to be an external method. External methods are implemented externally, typically using a language other than C#. Because an external method declaration provides no actual implementation, the method-body of an external method simply consists of a semicolon.
Here's more elaborate answer.