示例#1
0
        public void VisitInitializerExpression(InitializerExpressionSyntax node)
        {
            if (node == null)
                throw new ArgumentNullException("node");

            node.Validate();

            ExpressionStart(node);

            if (node.Expressions.Count == 0)
            {
                _writer.EmptyBlock();
            }
            else
            {
                _writer.BeginBlock();

                var wrapStyle = _writer.Configuration.LineBreaksAndWrapping.LineWrapping.WrapObjectAndCollectionInitializers;

                for (int i = 0; i < node.Expressions.Count; i++)
                {
                    _writer.WriteIndent();

                    node.Expressions[i].Accept(this);

                    if (i != node.Expressions.Count - 1)
                    {
                        _writer.WriteSyntax(Syntax.Comma);

                        if (wrapStyle != Configuration.WrapStyle.SimpleWrap)
                            _writer.Break(wrapStyle == Configuration.WrapStyle.ChopAlways);

                        _writer.WriteSpace();
                    }
                    else
                    {
                        _writer.WriteLine(true);
                    }
                }

                _writer.EndBlock();
            }

            ExpressionEnd(node);
        }