Baking IL With DynamicMethod
May 31st, 2009 by TrilobyteAt the moment I am building a new script engine which is consists of text and expressions embedded in them. Those expressions are basically calls to functions and have any number of arguments. The implementation of those functions is done in C#.
At compile time I don’t know which methods are going to be called so I have to invoke them at runtime. The most obvious way to do that is to use the reflection API of .NET to do a late bound method call. Although, IMHO, this is a perfectly valid solution to this problem it isn’t exactly fast.
System.Reflection.Emit.DynamicMethod is a better alternative for late bound method invocation when it comes to performance. Although it requires you to write Intermediate Language (IL) it is actually quite easy to use.