public static Instruction[] CreateLdType(this ILProcessor ilgen, TypeReference type) { return(new Instruction[] { ilgen.Create(OpCodes.Ldtoken, type), ilgen.Create(OpCodes.Call, Net2Resolver.GetMethod(typeof(Type), nameof(Type.GetTypeFromHandle))) }); }
public void EmitLdAction() { var module = method.DeclaringType.Module; var localCaptureParams = new VariableDefinition(captureParams.FieldType); var localLambdaKlass = new VariableDefinition(newKlass); ILTag.Output(ilgen, "[Begin EmitLdAction]"); int hasThis = method.IsStatic ? 0 : 1; ilgen.Emit(OpCodes.Ldc_I4, method.Parameters.Count); ilgen.Emit(OpCodes.Newarr, module.TypeSystem.Object.GetElementType()); ilgen.Emit(OpCodes.Stloc, localCaptureParams); ilgen.Emit(OpCodes.Newobj, newKlassCtor); ilgen.Emit(OpCodes.Stloc, localLambdaKlass); if (method.IsStatic == false) { ilgen.Emit(OpCodes.Ldloc, localLambdaKlass); ilgen.Emit(OpCodes.Ldarg_0); ilgen.Emit(OpCodes.Stfld, @this); } ILTag.Output(ilgen, "----LdArgs"); for (int i = 0; i < method.Parameters.Count; i++) { ilgen.Emit(OpCodes.Ldloc, localCaptureParams); ilgen.Emit(OpCodes.Ldc_I4, i + hasThis); ilgen.Emit(OpCodes.Ldarg, i + hasThis); if (method.Parameters[i].ParameterType.IsValueType) { ilgen.Emit(OpCodes.Box, method.Parameters[i].ParameterType); } ilgen.Emit(OpCodes.Stelem_Ref); } var createDelegate = Net2Resolver.GetMethod(typeof(Delegate), nameof(Delegate.CreateDelegate), new Type[] { typeof(Type), typeof(object), typeof(string) }); ILTag.Output(ilgen, "----Call CreateDeleagate"); ilgen.EmitType(module.Import(typeof(Rinity.Impl.RiniAction))); ilgen.Emit(OpCodes.Ldloc, localLambdaKlass); ilgen.Emit(OpCodes.Ldstr, newMethod.Name); ilgen.Emit(OpCodes.Call, createDelegate); ilgen.Emit(OpCodes.Castclass, module.Import(typeof(Rinity.Impl.RiniAction))); ILTag.Output(ilgen, "[End EmitLdAction]"); method.Body.Variables.Add(localLambdaKlass); method.Body.Variables.Add(localCaptureParams); }
public static Instruction CreateCallStringConcat(this ILProcessor ilgen) { return(ilgen.Create(OpCodes.Call, Net2Resolver.GetMethod(nameof(String), nameof(String.Concat), new Type[] { typeof(string), typeof(string) }))); }
public static void EmitType(this ILProcessor ilgen, TypeReference type) { ilgen.Emit(OpCodes.Ldtoken, type); ilgen.Emit(OpCodes.Call, Net2Resolver.GetMethod(typeof(Type), nameof(Type.GetTypeFromHandle))); }