Beispiel #1
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);
        }