Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of MethodInfo.MetadataToken

What is the token normally used for? More importantly, if I have a MetadataToken, can I get back the MethodInfo object?

like image 355
Arun Satyarth Avatar asked Jul 28 '15 14:07

Arun Satyarth


1 Answers

The metadata token is something that is part of the CIL specification for how data is organized. It's largely something you never need to care about.

More specifically, the metadata token is a tuple of a table identifier and a resource identifier.

You cannot rely on a metadata token to remain consistent between compiles, so I would not use it to identify a method.

You can use Module.ResolveMethod to convert a metadata token back to a MethodBase. MethodBase is the base type for MethodInfo. If the metadata token is for a method (as opposed to a constructor), then you should be able to cast it to a MethodInfo.

An assembly is made up of one or more modules, but practically an assembly only contains a single module - the C# and VB.NET compilers do not produce multi-module assemblies.

like image 87
vcsjones Avatar answered Oct 30 '22 08:10

vcsjones