O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

MethodRental

Synopsis

This class can be used to swap a method “body” (the MSIL code inside the method). To do this, use the static SwapMethodBody() method, and specify the target Type, the token of the method that should receive the new body, a pointer to the new method, the size of the new method, and a flag specifying the type of compilation using the appropriate field constant (either JitImmediate or JitOnDemand). The IntPtr to the new method body should point to an array of bytes that contain the IL for the method’s header and body.

public sealed class MethodRental {
// Public Static Fields
   public const field int JitImmediate;                          // =1
   public const field int JitOnDemand;                           // =0
                  // Public Static Methods
   public static method void SwapMethodBody(Type cls, 
        int methodtoken, IntPtr rgIL, int methodSize, 
        int flags);  
}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required