This project is read-only.

How do I work with the Mutable Code Model

Add a new type to the module

If you are adding a new type to a module in the mutable code model, be sure to add it to the flatListOfTypes, which is a field on the mutator. Otherwise you will get assertions in PEWrite when the index for your type is not found.

Create a generic method

To create a generic method, use new MethodDefinition() and set the CallingConvention to Generic. Then create new GenericMethodParameters and add them to the method's GenericParameter list. The generic method parameter's DefiningMethod should be set to the method it appears on.

In the end, this looks about as follows:
   MethodDefinition myGenericMethod = new MethodDefinition()
     Body = body,
     CallingConvention = CallingConvention.Generic,
     ContainingType = myType,
     Name = genericMethodName,
     Type = genericMethodReturnType,
     Visibility = TypeMemberVisibility.Public,
     IsStatic = true,
     InternFactory = host.InternFactory,
   var typeArg = new GenericMethodParameter()
     Name = host.NameTable.GetNameFor("TParameter"),
     DefiningMethod = myGenericMethod,
     InternFactory = host.InternFactory,

Last edited Apr 21, 2009 at 5:47 PM by MaF, version 5


No comments yet.