本文整理汇总了C#中System.Reflection.Emit.ILGenerator.EmitCalli方法的典型用法代码示例。如果您正苦于以下问题:C# ILGenerator.EmitCalli方法的具体用法?C# ILGenerator.EmitCalli怎么用?C# ILGenerator.EmitCalli使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ILGenerator
的用法示例。
在下文中一共展示了ILGenerator.EmitCalli方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
/// <summary>
/// Generate MSIL code to emit a Calli indirect call with the given
/// calling convention, return type and array of parameter types.
/// </summary>
/// <param name="il">ILGenerator object</param>
public override void Generate(ILGenerator il)
{
if (il == null) {
throw new ArgumentNullException("il");
}
if (Deleted) {
return;
}
il.EmitCalli(OpCodes.Calli, _conv, _returnType, _parameterTypes, null);
}
示例2: TestEmitCalliWithNullReturnType
public void TestEmitCalliWithNullReturnType ()
{
MethodBuilder mb = tb.DefineMethod ("F",
MethodAttributes.Public | MethodAttributes.Static, null, new Type [] { typeof (IntPtr) });
mb.SetImplementationFlags (MethodImplAttributes.NoInlining);
il_gen = mb.GetILGenerator ();
il_gen.Emit (OpCodes.Ldarg_0);
il_gen.EmitCalli (OpCodes.Calli, CallingConvention.StdCall, null, Type.EmptyTypes);
il_gen.Emit (OpCodes.Ret);
Type dynt = tb.CreateType ();
dynt.GetMethod ("F", BindingFlags.Public | BindingFlags.Static).Invoke (
null, new object [] { Marshal.GetFunctionPointerForDelegate (new FooFoo (Foo)) });
}
示例3: EmitIL
//.........这里部分代码省略.........
case OperationCode.Stelem:
case OperationCode.Stobj:
case OperationCode.Unbox:
case OperationCode.Unbox_Any:
//^ assume operation.Value is ITypeReference;
ilGenerator.Emit(OpCodeFor(operation.OperationCode), this.loader.mapper.GetType((ITypeReference)operation.Value));
continue;
case OperationCode.Call:
case OperationCode.Callvirt:
case OperationCode.Jmp:
case OperationCode.Ldftn:
case OperationCode.Ldvirtftn:
//TODO: if the reference has extra arguments, use EmitCall
//^ assume operation.Value is IMethodReference;
var methodBase = this.loader.mapper.GetMethod((IMethodReference)operation.Value);
if (methodBase.IsConstructor)
ilGenerator.Emit(OpCodeFor(operation.OperationCode), (ConstructorInfo)methodBase);
else
ilGenerator.Emit(OpCodeFor(operation.OperationCode), (MethodInfo)methodBase);
break;
case OperationCode.Newobj:
//^ assume operation.Value is IMethodReference;
ilGenerator.Emit(OpCodes.Newobj, (ConstructorInfo)this.loader.mapper.GetMethod((IMethodReference)operation.Value));
break;
case OperationCode.Calli:
//^ assume operation.Value is IFunctionPointerTypeReference;
var functionPointer = (IFunctionPointerTypeReference)operation.Value;
var callingConvention = MemberBuilderAllocator.GetCallingConvention(functionPointer.CallingConvention);
var returnType = loader.mapper.GetType(functionPointer.Type);
var parameterTypes = new Type[IteratorHelper.EnumerableCount(functionPointer.Parameters)];
int i = 0; foreach (var parameter in functionPointer.Parameters) parameterTypes[i++] = loader.mapper.GetType(parameter.Type);
var optionalParameterTypes = new Type[IteratorHelper.EnumerableCount(functionPointer.ExtraArgumentTypes)];
i = 0; foreach (var parameter in functionPointer.ExtraArgumentTypes) parameterTypes[i++] = loader.mapper.GetType(parameter.Type);
ilGenerator.EmitCalli(OpCodes.Calli, callingConvention, returnType, parameterTypes, optionalParameterTypes);
continue;
case OperationCode.Ldarg:
case OperationCode.Ldarga:
case OperationCode.Starg:
if (operation.Value == null) //it's the this arg, which does not have an IParameterDefinition
ilGenerator.Emit(OpCodeFor(operation.OperationCode), (short)0);
else
ilGenerator.Emit(OpCodeFor(operation.OperationCode), GetParameterIndex((IParameterDefinition)operation.Value));
continue;
case OperationCode.Ldarg_S:
case OperationCode.Ldarga_S:
case OperationCode.Starg_S:
if (operation.Value == null) //it's the this arg, which does not have an IParameterDefinition
ilGenerator.Emit(OpCodeFor(operation.OperationCode), (byte)0);
else
ilGenerator.Emit(OpCodeFor(operation.OperationCode), (byte)GetParameterIndex((IParameterDefinition)operation.Value));
continue;
case OperationCode.Ldc_I4:
//^ assume operation.Value is int;
ilGenerator.Emit(OpCodes.Ldc_I4, (int)operation.Value);
continue;
case OperationCode.Ldc_I4_S:
//^ assume operation.Value is int;
ilGenerator.Emit(OpCodes.Ldc_I4_S, (sbyte)(int)operation.Value);
continue;
case OperationCode.Ldc_I8:
//^ assume operation.Value is long;
ilGenerator.Emit(OpCodes.Ldc_I8, (long)operation.Value);
continue;
case OperationCode.Ldc_R4:
//^ assume operation.Value is float;
ilGenerator.Emit(OpCodes.Ldc_R4, (float)operation.Value);