I'd like to create dynamically some method, which will accept single parameter - instance of class A and then will execute method B in passed instance of A. B has parameter of type int. So here is the schema:
dynamicMethod(A a){
a.B(12);
}
Here what I tried:
DynamicMethod method = new DynamicMethod(string.Empty, typeof(void), new[] { typeof(A) }, typeof(Program));
MethodInfo methodB = typeof(A).GetMethod("B", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[] { }, null);
ILGenerator gen = method.GetILGenerator();
gen.Emit(OpCodes.Nop);
gen.Emit(OpCodes.Ldarg_0);
gen.Emit(OpCodes.Ldarg_S, 100);
gen.Emit(OpCodes.Call, methodB);
But compiler tells me that CLR doesn't found the method. Could you help me with it?