vendredi 23 septembre 2016

Convert IL bytearray back to methodinfo

Assume we have a very simple action:

Action<string> hello = s => Console.WriteLine("Hello, {0}!", s);

Now I want to clone it. So I write:

Action<string> hello = s => Console.WriteLine("Hello, {0}!", s);
var ilCode = hello.Method.GetMethodBody().GetILAsByteArray();
Action<string> helloClone = GetMethodFromILByteArray(ilCode);
helloClone("Stackoverflow");

The problem is that I don't know how to implement GetMethodFromILByteArray. Firstly I looked on Emit, but failed to found anything like pass byte code array here and we'l return MethodInfo/Delegate/something.

How could it be implemented?





Aucun commentaire:

Enregistrer un commentaire