Lors de la création d'une méthode dynamique, j'aimerais émettre une instruction qui charge une référence déjà existante sur la pile.
En clair, j'ai ceci :
Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 class Foo { Action<object>GetBarMethod(...){ ConstructorInfo ci = typeof(Foobar).GetConstructor(new Type[]{typeof(Foobar)}); DynamicMethod dm = new DynamicMethod(...); IlGenerator il = dm.GetILGenerator(...); // Ici quelque chose pour charger la référence "this" sur la pile il.Emit(Opcodes.Newobj, ci); il.Emit(Opcodes.ret); } }
Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 class Foobar { public Foobar(Foo foo){...} }
Quelqu'un a déjà fait ça ou sait comment faire ?
Partager