MethodBuilder.CreateMethodBody

  • Thread starter Thread starter shark
  • Start date Start date
S

shark

Hi,

MethodBuilder.CreateMethodBody creates the body of the method using a
supplied byte array of Microsoft intermediate language (MSIL) instructions.
Is there any way to create and compile method at runtime created from byte[]
of c# code?
i.e.
public int sum(int a, int b)
{
return a+b;
}

How to create such method ?

Thx
 
shark,

In order to do this, you would have to use the compiler directly (there
are classes in the Microsoft.CSharp namespace to do this). You would feed
it the code, and then it would return the compiled code to you.

However, you might be better off trying to use IL, especially if you are
creating temporary pieces of code.

Hope this helps.
 
Although I'm not 100% sure, I somewhat recall that "CodeDom" is what
you're probably looking for.

Cheers,
Stefan.
 
Back
Top