本文整理汇总了C#中Mono.Cecil.Cil.ILProcessor.InsertInstructionsBefore方法的典型用法代码示例。如果您正苦于以下问题:C# ILProcessor.InsertInstructionsBefore方法的具体用法?C# ILProcessor.InsertInstructionsBefore怎么用?C# ILProcessor.InsertInstructionsBefore使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mono.Cecil.Cil.ILProcessor
的用法示例。
在下文中一共展示了ILProcessor.InsertInstructionsBefore方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WeaveOnComplete
private void WeaveOnComplete(MethodDefinition targetMethod, ILProcessor ilp, VariableDefinition aspectInstance, VariableDefinition correlation)
{
if (_onComplete != null)
{
var last = targetMethod.Body.Instructions.Last();
if (last.OpCode == OpCodes.Ret)
{
var insertBefore = last.Previous;
while (insertBefore.OpCode != OpCodes.Nop && insertBefore.OpCode != OpCodes.Br_S)
{
insertBefore = insertBefore.Previous;
}
Instruction loadReturn = null;
//if it's a br_s then we are returning a value.
if (insertBefore.OpCode == OpCodes.Br_S)
{
loadReturn = ilp.Copy(insertBefore.Next);
}
var onCompleteInstructions = GetOnCompleteInstructions(targetMethod, ilp, aspectInstance, correlation, loadReturn).ToArray();
//Place this code before the last nop or br_s so that the onException can place itself correctly.
ilp.InsertInstructionsBefore(insertBefore, onCompleteInstructions);
}
}
}