本文整理汇总了C#中Mono.Cecil.Cil.CilWorker.PackageReturnValue方法的典型用法代码示例。如果您正苦于以下问题:C# CilWorker.PackageReturnValue方法的具体用法?C# CilWorker.PackageReturnValue怎么用?C# CilWorker.PackageReturnValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.Cil.CilWorker
的用法示例。
在下文中一共展示了CilWorker.PackageReturnValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Replace
private void Replace(CilWorker IL, Instruction oldInstruction, MethodReference targetMethod, MethodDefinition hostMethod, Instruction endLabel, Instruction callOriginalMethod)
{
var returnType = targetMethod.ReturnType.ReturnType;
var module = hostMethod.DeclaringType.Module;
if (!hostMethod.IsStatic)
GetInstanceProvider(IL);
var pushInstance = hostMethod.HasThis ? IL.Create(OpCodes.Ldarg_0) : IL.Create(OpCodes.Ldnull);
// If all else fails, use the static method replacement provider
IL.Append(pushInstance);
IL.Emit(OpCodes.Ldloc, _invocationInfo);
IL.Emit(OpCodes.Call, _getStaticProvider);
IL.Emit(OpCodes.Stloc, _staticProvider);
var restoreArgumentStack = IL.Create(OpCodes.Nop);
var callReplacement = IL.Create(OpCodes.Nop);
var useStaticProvider = IL.Create(OpCodes.Nop);
#region Use the instance method replacement provider
IL.Emit(OpCodes.Ldloc, _instanceProvider);
IL.Emit(OpCodes.Brfalse, useStaticProvider);
EmitCanReplace(IL, hostMethod, _instanceProvider);
IL.Emit(OpCodes.Ldloc, _canReplaceFlag);
IL.Emit(OpCodes.Brfalse, useStaticProvider);
EmitGetMethodReplacement(IL, hostMethod, _instanceProvider);
IL.Emit(OpCodes.Ldloc, _replacement);
IL.Emit(OpCodes.Brtrue, callReplacement);
#endregion
IL.Append(useStaticProvider);
// if (!MethodReplacementProvider.CanReplace(info))
// CallOriginalMethod();
EmitCanReplace(IL, hostMethod, _staticProvider);
IL.Emit(OpCodes.Ldloc, _canReplaceFlag);
IL.Emit(OpCodes.Brfalse, restoreArgumentStack);
EmitGetMethodReplacement(IL, hostMethod, _staticProvider);
IL.Append(callReplacement);
// if (replacement == null)
// CallOriginalMethod();
IL.Emit(OpCodes.Ldloc, _replacement);
IL.Emit(OpCodes.Brfalse, restoreArgumentStack);
EmitInterceptorCall(IL);
IL.PackageReturnValue(module, returnType);
IL.Emit(OpCodes.Br, endLabel);
IL.Append(restoreArgumentStack);
// Reconstruct the method arguments if the interceptor
// cannot be found
// Push the target instance
ReconstructMethodArguments(IL, targetMethod);
// Mark the CallOriginalMethod instruction label
IL.Append(callOriginalMethod);
// Call the original method
IL.Append(oldInstruction);
}
示例2: InvokeInterceptor
private static void InvokeInterceptor(ModuleDefinition module, CilWorker IL,
VariableDefinition methodReplacement, TypeReference returnType, VariableDefinition invocationInfo)
{
var interceptMethod = module.ImportMethod<IInterceptor>("Intercept");
IL.Emit(OpCodes.Ldloc, methodReplacement);
IL.Emit(OpCodes.Ldloc, invocationInfo);
IL.Emit(OpCodes.Callvirt, interceptMethod);
IL.PackageReturnValue(module, returnType);
}