Beispiel #1
0
        internal static BoundBlock BindBlock(BlockSyntax node, DiagnosticBag diagnostics, Binder blockBinder)
        {
            Debug.Assert(blockBinder != null);

            var syntaxStatements = node.Statements;
            int nStatements = syntaxStatements.Count;

            ArrayBuilder<BoundStatement> boundStatements = ArrayBuilder<BoundStatement>.GetInstance(nStatements);

            for (int i = 0; i < nStatements; i++)
            {
                var boundStatement = blockBinder.BindStatement(syntaxStatements[i], diagnostics);
                boundStatements.Add(boundStatement);
            }

            if (blockBinder.IsDirectlyInIterator)
            {
                var method = blockBinder.ContainingMemberOrLambda as SourceMethodSymbol;
                if ((object)method != null)
                {
                    method.IteratorElementType = blockBinder.GetIteratorElementType(null, diagnostics);
                }
                else
                {
                    Debug.Assert(!diagnostics.IsEmptyWithoutResolution);
                }
            }

            return new BoundBlock(node, blockBinder.GetDeclaredLocalsForScope(node), boundStatements.ToImmutableAndFree());
        }