Alex Rivera | Logout

Practical example of Dynamic method?

Asked 2009-12-25T07:19:18.153
20

I want to learn dynamic method and its practical example using c#.
Is there any relation between dynamic method and Reflection?
Please help me.

Edit
Report

1 Answer

5

You can create a method via DynamicMethod class.

DynamicMethod squareIt = new DynamicMethod(
    "SquareIt", 
    typeof(long), 
    methodArgs, 
    typeof(Example).Module);

ILGenerator il = squareIt.GetILGenerator();
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Conv_I8);
il.Emit(OpCodes.Dup);
il.Emit(OpCodes.Mul);
il.Emit(OpCodes.Ret);

Fully commented example on MSDN
I should note that the development using this method is very slow and not very useful.

answered 2009-12-25T07:52:16.020

Your Answer