I have been using System.Reflection.Emit for a while and find it (who is not?) As painful as error prone.
Do you know if there is a good shell around the IL generator that I can rely on to emit IL in a safer and easier way than with direct SRE playback?
Edit:
I know that manipulating expression trees is ultimately simpler and safer than directly emitting IL, but they also have some limitations right now. I cannot create blocks of code, use loops, declare and work with multiple locals, etc. We need to wait until .NET 4 comes out :)
In addition, I am dealing with a code base that already relies on SRE.
Obviously, ILGenerator does everything I need. But I will be grateful for the help in managing it. When I mean the ILGenerator shell, which remains at a fairly low level, I think of something that can provide methods such as:
// Performs a virtual or direct call on the method, depending if it is a // virtual or a static one. Call(MethodInfo methodInfo) // Pushes the default value of the type on the stack, then emit // the Ret opcode. ReturnDefault(Type type) // Test the object type to emit the corresponding push // opcode (Ldstr, Ldc_I*, Ldc_R*, etc.) LoadConstant(object o)
These are really 3 naive examples, but this may be enough to demonstrate what I expect. We can see this as a set of extension methods, but it would be nice to have support for conditional statements and loops, for example, in RunSharp . In fact, RunSharp is pretty close to what I want, but it abstracts too far ILGenerator and does not reveal all its functionality.
I canβt remember where, but I have already seen such an assistant in an open source project.
Romain verdier
source share