Mono.Cecil.Cil.OpCode is a class in the Mono.Cecil package library that provides an abstraction layer over CIL (Common Intermediate Language) opcodes, which are essentially instructions that are executed by the .NET runtime.
Example 1: OpCode.Ldc_I4 This OpCode pushes a 32-bit integer value onto the evaluation stack. To use this OpCode, the following code can be used:
var ilProcessor = method.Body.GetILProcessor(); ilProcessor.Emit(OpCodes.Ldc_I4, 42);
This example demonstrates how to use the Ldc_I4 OpCode to push the value 42 onto the evaluation stack.
Example 2: OpCode.Call This OpCode calls the method specified by the metadata token. To use this OpCode, the following code can be used:
var ilProcessor = method.Body.GetILProcessor(); var methodReference = moduleDefinition.Import(typeof(Console).GetMethod("WriteLine", new[] { typeof(string) })); ilProcessor.Emit(OpCodes.Call, methodReference);
This example demonstrates how to use the Call OpCode to call the WriteLine method of the Console class.
In summary, the Mono.Cecil.Cil.OpCode provides a convenient way to work with command codes in C# code. It is included as part of the Mono.Cecil package library.
C# (CSharp) Mono.Cecil.Cil OpCode - 60 examples found. These are the top rated real world C# (CSharp) examples of Mono.Cecil.Cil.OpCode extracted from open source projects. You can rate examples to help us improve the quality of examples.