all groups > dotnet clr > july 2005 >
You're in the

dotnet clr

group:

Module.ResolveType(int, Type[], Type[]) example



Module.ResolveType(int, Type[], Type[]) example Sacha Faust
7/18/2005 4:31:12 AM
dotnet clr: Anyone as a code sample that use the new Module.Resolve(int, Type[], Type[])
call in framework 2.0?

Re: Module.ResolveType(int, Type[], Type[]) example Gael Fraiteur
7/19/2005 11:28:23 AM
PostSharp uses it. You can download the code at
http://gael.fraiteur.net/postsharp.aspx and have a look. But it may be a
little difficult to understand the whole flow...

Maybe the following will help:

These methods (ResolveType, ResolveMethod, ...) should be used in the
context of a disassembler or "binary IL reader".

In binary IL code, methods, fields, types and so on are referenced to by
"tokens", i.e. integers. These integers refer to entries in the metadata
tables.

A typical use scenario involving ResolveType is:

1. You want to disassemble a method.
2. You get the MethodBase of the method to disassemble. Do the following to
get the generic arguments in the context of this method.

Type[] typeGenericArguments = method.DeclaringType.GetGenericArguments() ;
Type[] methodGenericArguments = method.GetGenericArguments();

3. You get a byte array containing the IL code.

4. While reading this byte array, you discover an instruction expecting a
type metadata token (for instance a cast instruction).

5. You want to know what Type refers the token to. Use:

Type type = module.ResolveType( token, typeGenericArguments,
methodGenericArguments );

Hope it helped.

Gael



[quoted text, click to view]

AddThis Social Bookmark Button