C # call
Math.Pow(2,3);
in ILDASM:
ldc.r8 2. ldc.r8 3. call float64[mscorlib]System.Math::Pow(float64, float64)
Can someone please tell me how to emit this call statement via ILGenerator? Thanks.
Here is an example of constructing a dynamic method that will call the static method Math.Pow(double, double) :
Math.Pow(double, double)
using System; using System.Linq; using System.Reflection.Emit; class Program { static void Main() { // define the signature of the dynamic method var powIt = new DynamicMethod( "PowIt", typeof(double), new Type[] { typeof(double), typeof(double) }, typeof(Program).Module ); // get a MethodInfo pointer to the Math.Pow(double, double) static // method that we are willing to use in our dynamic method var pow = typeof(Math).GetMethod("Pow", new[] { typeof(double), typeof(double) }); var il = powIt.GetILGenerator(); // Push the first argument onto the evaluation stack il.Emit(OpCodes.Ldarg_0); // Push the second argument onto the evaluation stack il.Emit(OpCodes.Ldarg_1); // Invoke the Math.Pow static method that we obtained a MethodInfo earlier // by passing the two arguments that are on the evaluation stack il.Emit(OpCodes.Call, pow); // Return from the method pushing a return value from the callee evaluation stack onto the caller evaluation stack il.Emit(OpCodes.Ret); // build a delegate from the dynamic method var func = (Func<double, double, double>)powIt.CreateDelegate(typeof(Func<double, double, double>)); // Now invoke the delegate Console.WriteLine(func(2, 3)); } }
Source: https://habr.com/ru/post/903528/More articles:exchange letters in a string in python - pythonRotation of object unity, rotating with the wrong value - c #Creating a table of contents - wolfram-mathematicaIn any case, with the Entity Framework Code First of all, to get a good idea about the structure of the class? - entity-framework-4.1the size of the next datagram queue - UDP - c #How do I swap letters around input in python? - pythonTarget c division of two ints - objective-cWhy is there a write (int b) method for an OutputStream? - javaThe stat_smooth limit for a specific range is rDomain limit when using socket.io? - socket.ioAll Articles