コード例 #1
0
        public override void OnBinaryExpression(BinaryExpression node)
        {
            if (node.IsDeclarationStatement())
            {
                var localDeclaration = (InternalLocal)node.Left.Entity;
                if (localDeclaration.OriginalDeclaration == null)
                {
                    var closureBlock = node.GetAncestor <Block>();
                    if (closureBlock != null && closureBlock == node.ParentNode.ParentNode)
                    {
                        closureBlock.Statements.Remove((ExpressionStatement)node.ParentNode);  // Step 4: removes the local initialization

                        var capturedVariables = CollectCapturedParameters(closureBlock);

                        IntroduceLocalVariablesForCapturedLocals(closureBlock, capturedVariables);

                        FixCapturedVariableReferences(closureBlock, capturedVariables);

                        RemoveLocalVariableDeclaration(closureBlock, localDeclaration);

                        RemoveClosureInstanceInitialization(closureBlock);
                    }
                }
                return;
            }

            base.OnBinaryExpression(node);
        }