In the newest version of the .NET framework, version 4.5, the MethodBuilder class has a method called SetMethodBody
that I believe is exactly what I'm looking at as an alternative to using ILGenerator (which is annoying and limited in odd ways). The documentation can be found here, although since .NET 4.5 is not out yet, it is not fully documented. I can supply all but two of the arguments, but the rest I will need help with.
The first that I don't understand is byte[] localSignature
, the third argument. MSDN states that it is "An array of bytes that contain the serialized local variable structure. Specify null if the method has no local variables." The trouble is, that's all it says, and I can't find out the format of a "serialized local variable signature." I have tried looking in the ECMA-335 spec, but all I have found is how to specify the local variables in unassembled CIL. If anybody could help me figure this out, it would be much appreciated.
Also, the last argument is IEnumerable<int> tokenFixups
, which is "A collection of values that represent offsets in il, each of which specifies the beginning of a token that may be modified. Specify null if the method has no tokens that have to be modified.". I suspect that I won't need to use these, but I'd like to know what they are anyway.
Thanks, Brandon