reflection.emit

Call a method using a MethodInfo instance on the stack using Reflection.Emit

I am using Reflection.Emit to build a mathematical expression parser (e.g. 2+2). A class takes in an infix expression (e.g. 2+2), turns it into a postfix expression (e.g. 2 2 +), and then another class compiles that postfix expression into IL and creates a DynamicMethod. From there, the expression can be evaluated as if it had been creat...

Getting the default constructor of a generic abstract class

Hi. I have a generic abstract base class from which I would like to derive from a dynamic type built through reflection.emit. Also I need to customize the derived class default constructor to initialize some fields. To build the default constructor of the derived class correctly I need to obtain the default constructor of the base class...

.NET: Clone an Existing Method Dynamically with Reflection.Emit

There are plenty of threads on how to create a Method using Reflection.Emit but I cannot find any on Cloning or copying an Existing Method. I would like to copy an existing class and add a few more additional fields to it. I am having trouble copying the methods. I have read that you cannot simply take the IL Code from the body because...

Formatter that generates IL code for String.Format

I was looking for an object formatter and templater. http://haacked.com/archive/2009/01/14/named-formats-redux.aspx I looked into HenriFormatter and when check performance found that for the same object Type first invocation - causes 15x more time than for next - 15k ticks, second was around 1k. I become digg, and found that its using ...

Identifying Reflection.Emit-generated assemblies

Is there a simple way to identify Reflection.Emit-generated assemblies? When processing all assemblies loaded into an application domain, Assembly instances of dynamically generated assemblies don't behave the same as for standard assemblies. For example, accessing the CodeBase property leads to an exception: string codeBase; try { ...

Is there a straightforward way to copy a Type using reflection?

I realize this is a very strange question. Let me just say that I have my reasons. (I tend to write very long, wordy questions; I want to keep this one short.) If I have some type T, can I use reflection to define a new type, let's call it T2, that will basically be identical to T? What I'm looking for is essentially a dynamic way to do...

Is it possible to get design-time code completion for dynamic types?

I'm looking into generating types dynamically, ie. TypeBuilder, Reflection.Emit.. Is it ever possible to get design-time code completion for such created types? i.e typename recognition, list of properties after typing "obj1." and such. Full Context: Trying to generate entities and data access objects corresponding to database tables in...

Open Emitted assembly in Reflector

I'm generating a dynamic assembly using Reflection.Emit which includes a single class. I have a bug which is causing a BadImageException. To resolve this I need to see the compiled code, and therefore I'm saving the dynamic assembly to disk. I've already tried PEVerify against the assembly which seems to think there are no errors. I now...

LambdaExpression CompileToMethod

I Have a few lines of code public void CreateMethod<TContract>(Expression<Action<TContract>> method) { var innerMethod = Builder.DefineMethod("SomeName",MethodAttributes.Private); method.CompileToMethod(innerMethod); //more code } However the second line fails. I've tried with different versions of DefineMethod with little lu...