0

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?

Matias Cicero
  • 25,439
  • 13
  • 82
  • 154

1 Answers1

4

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.

Community
  • 1
  • 1
Ondrej Janacek
  • 12,486
  • 14
  • 59
  • 93