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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.