private bool Process(ILNode node, ref int stackSize) { while (node != null) { switch (node.NodeType) { case ILNodeType.Block: { var block = (ILBlock)node; // Catch handler, filter handler, and filter blocks begin with stack of 1 (Exception). switch (block.BlockType) { case ILBlockType.ExceptionFilter: { if (stackSize < 1) { stackSize = 1; } } break; case ILBlockType.ExceptionHandle: { var handler = (ILExceptionHandlerBlock)block; if (handler.HandlerType == ExceptionHandlerType.Catch || handler.HandlerType == ExceptionHandlerType.Filter) { if (stackSize < 1) { stackSize = 1; } } } break; } if (block.FirstChild != null) { if (!Process(block.FirstChild, ref stackSize)) { return(false); } } } break; case ILNodeType.Instruction: { var instruction = (ILInstruction)node; // Stack size is already calcualated. int currentStackSize; if (_stackSizeByInstruction.TryGetValue(instruction, out currentStackSize) && currentStackSize >= stackSize) { return(false); } Process(instruction, ref stackSize); } break; } node = node.NextSibling; } return(true); }