示例#1
0
 public AroundInstructionWeaver(IInstructionDescription description, MethodDefinition method, AroundAdvice advice, int priority)
     : base(method, advice, priority)
 {
     instruction      = description.Instruction;
     originalOperand  = description.Instruction.Operand;
     this.description = description;
 }
示例#2
0
        public override void Weave()
        {
            if (instruction != null)
            {
                iDescriptor = InstructionDescriptor.Instance.GetDescription(instruction);
            }

            var start        = il.Create(OpCodes.Nop);
            var startFinally = il.Create(OpCodes.Nop);
            var end          = il.Create(OpCodes.Nop);

            SplitInstructions();
            il.AppendAll(beforeInstructions);
            AppendProlog();
            il.Append(start);
            il.AppendAll(affectedInstructions);
            il.Append(OpCodes.Leave_S, end);
            il.Append(startFinally);
            AppendEpilog();
            il.Append(OpCodes.Endfinally);
            il.Append(end);

            il.AppendAll(afterInstructions);

            var handler = new ExceptionHandler(ExceptionHandlerType.Finally)
            {
                TryStart     = start,
                TryEnd       = startFinally,
                HandlerStart = startFinally,
                HandlerEnd   = end
            };

            method.Body.ExceptionHandlers.Add(handler);
        }