A mechanism for extracting specific IL (.NET Intermediate Language) signatures from an assembly

I have a list of about 25 types found in the Microsoft.NET assembly mscorlib.dll, where I need to extract the IL signatures of the class and its members. I want one file for each type, with each signature on one line. So, for example, take the type

System.Collections.Generic.Comparer<T> 

I want to extract the following from the assembly for this type (there are some private members that I do not need, but I can handle this manually if necessary).

 .class public abstract auto ansi serializable beforefieldinit System.Collections.Generic.Comparer`1<T> extends System.Object implements System.Collections.IComparer, class System.Collections.Generic.IComparer`1<!T> .method family hidebysig specialname rtspecialname instance void .ctor() cil managed .method public hidebysig newslot abstract virtual instance int32 Compare(!T x, !T y) cil managed .method private hidebysig newslot virtual final instance int32 System.Collections.IComparer.Compare(object x, object y) cil managed .property class System.Collections.Generic.Comparer`1<!T> Default() { .get class System.Collections.Generic.Comparer`1<!T> System.Collections.Generic.Comparer`1::get_Default() } 

So, I thought of four ways to achieve this:

  • Manually cut and paste each signature from each type manually into text files from ildasm (either directly or through a dump of mscorlib.dll). Some of the types are quite long, so this can become tedious. And this is definitely not a good long-term solution if I need to do more.

  • Write a tool that uses Reflection to try to get all the signatures. At a high level, I thought about using something like psuedo-code [1] below.

  • Write a tool that uses string parsing on an IL ildasm dump to find types and get signatures

  • Use an existing tool to complete the task.

Does anyone know of an existing tool or mechanism that can help me accomplish my task? If not, any suggestions on which direction to go to get such an instrument? And if you have any ideas on how to do this, I would be happy to hear them.

[1]

 System.Reflection.GetType(string) Type.GetMethods() For each item in MethodInfo, GetMethodBody() GetILAsByteArray().ToString() Determine a way to get just the signature from the IL 
+1
source share
3 answers

The red gate reflector can make the cut and paste much faster.

+1
source

You can restore the method signature from the information found in MethodInfo. You do not need GetMethodBody - there is no subscription information there. MemberInfo.Name, MemberInfo.ReturnType, MemberInfo.GetParameters (), etc. It is all there.

+2
source

If you decide to get a signature from IL, you will need to write some kind of signature parser. David Broman has a sample posted in the MSDN code gallery here . It is not fully functional (in particular, you will need to add generic support), but it gives you a start.

+1
source

All Articles