Exemplo n.º 1
0
        public static void MarkBlockBefore(this CecilILGenerator il, ExceptionBlock block)
        {
            switch (block.blockType)
            {
            case ExceptionBlockType.BeginExceptionBlock:
                il.BeginExceptionBlock();
                return;

            case ExceptionBlockType.BeginCatchBlock:
                il.BeginCatchBlock(block.catchType);
                return;

            case ExceptionBlockType.BeginExceptFilterBlock:
                il.BeginExceptFilterBlock();
                return;

            case ExceptionBlockType.BeginFaultBlock:
                il.BeginFaultBlock();
                return;

            case ExceptionBlockType.BeginFinallyBlock:
                il.BeginFinallyBlock();
                return;

            case ExceptionBlockType.EndExceptionBlock:
                return;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 2
0
        internal void MarkBlockBefore(ExceptionBlock block, out Label?label)
        {
            label = null;
            switch (block.blockType)
            {
            case ExceptionBlockType.BeginExceptionBlock:
                if (debug)
                {
                    FileLog.LogBuffered(".try");
                    FileLog.LogBuffered("{");
                    FileLog.ChangeIndent(1);
                }
                label = il.BeginExceptionBlock();
                return;

            case ExceptionBlockType.BeginCatchBlock:
                if (debug)
                {
                    // fake log a LEAVE code since BeginCatchBlock() does add it
                    LogIL(OpCodes.Leave, new LeaveTry());

                    FileLog.ChangeIndent(-1);
                    FileLog.LogBuffered("} // end try");

                    FileLog.LogBuffered($".catch {block.catchType}");
                    FileLog.LogBuffered("{");
                    FileLog.ChangeIndent(1);
                }
                il.BeginCatchBlock(block.catchType);
                return;

            case ExceptionBlockType.BeginExceptFilterBlock:
                if (debug)
                {
                    // fake log a LEAVE code since BeginCatchBlock() does add it
                    LogIL(OpCodes.Leave, new LeaveTry());

                    FileLog.ChangeIndent(-1);
                    FileLog.LogBuffered("} // end try");

                    FileLog.LogBuffered(".filter");
                    FileLog.LogBuffered("{");
                    FileLog.ChangeIndent(1);
                }
                il.BeginExceptFilterBlock();
                return;

            case ExceptionBlockType.BeginFaultBlock:
                if (debug)
                {
                    // fake log a LEAVE code since BeginCatchBlock() does add it
                    LogIL(OpCodes.Leave, new LeaveTry());

                    FileLog.ChangeIndent(-1);
                    FileLog.LogBuffered("} // end try");

                    FileLog.LogBuffered(".fault");
                    FileLog.LogBuffered("{");
                    FileLog.ChangeIndent(1);
                }
                il.BeginFaultBlock();
                return;

            case ExceptionBlockType.BeginFinallyBlock:
                if (debug)
                {
                    // fake log a LEAVE code since BeginCatchBlock() does add it
                    LogIL(OpCodes.Leave, new LeaveTry());

                    FileLog.ChangeIndent(-1);
                    FileLog.LogBuffered("} // end try");

                    FileLog.LogBuffered(".finally");
                    FileLog.LogBuffered("{");
                    FileLog.ChangeIndent(1);
                }
                il.BeginFinallyBlock();
                return;
            }
        }