Ejemplo n.º 1
0
        private void WriteNode(string indent, FormattedNode node)
        {
            ContentNode content;

            if ((content = node as ContentNode) != null)
            {
                this.WriteContent(content);
            }
            else
            {
                ElementNode element;
                if ((element = node as ElementNode) != null)
                {
                    this.WriteElement(indent, element);
                }
                else
                {
                    AttributeNode attribute;
                    if ((attribute = node as AttributeNode) != null)
                    {
                        this.WriteAttribute(indent, attribute);
                    }
                    else
                    {
                        UnprocessedNode unprocessedNode;
                        if ((unprocessedNode = node as UnprocessedNode) == null)
                        {
                            return;
                        }
                        this.WriteUnprocessedNode(indent, unprocessedNode);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 protected static IndentingBehavior GetIndentingBehavior(FormattedNode node)
 {
     for (; node != null && !(node is RootNode); node = (FormattedNode)node.Parent)
     {
         if (node.SourceContextReference == null || node.SourceContextReference.SourceContext == null || (node.SourceContextReference.SourceContext.TextRange == null || node.SourceContextReference.SourceContext.IsCloned) || node.SourceContextReference.DocumentNode != null && node.SourceContextReference.DocumentNode.ContainerSourceContext == null && (node.Parent == null || !(node.Parent is RootNode) && (node.Parent.SourceContextReference == null || node.Parent.SourceContextReference.SourceContext != node.SourceContextReference.SourceContext.Parent)))
         {
             return(IndentingBehavior.FromContainer);
         }
     }
     return(IndentingBehavior.LeaveUnchanged);
 }
Ejemplo n.º 3
0
 public void WriteNode(FormattedNode node)
 {
     this.WriteNode(node.SourceContextReference != null ? node.SourceContextReference.GetIndent(this.settings.IndentString) : string.Empty, node);
 }
Ejemplo n.º 4
0
        private void WriteElement(string indent, ElementNode element)
        {
            ElementPersistenceSettings elementSettings = this.settings.GetElementSettings(typeof(object));

            XamlFormatter.XmlElementFormatting elementFormatting = this.GetElementFormatting(element);
            if (elementFormatting.LeadingWhitespace != null)
            {
                this.writer.SetWhitespace(elementFormatting.LeadingWhitespace);
                if (!this.writer.Started || this.writer.LineBreakCount > 0)
                {
                    if (element.IndentingBehavior == IndentingBehavior.FromContainer)
                    {
                        this.writer.SetIndent(indent);
                    }
                    else
                    {
                        indent = this.writer.Indent;
                    }
                }
            }
            else
            {
                this.writer.SetMinimumLineBreaks(elementSettings.LinesOutside);
                this.writer.SetIndent(indent);
            }
            XmlElementReference elementReference = (XmlElementReference)null;

            if (this.shouldUpdateSourceContext && element.SourceContextReference != null)
            {
                elementReference = element.SourceContextReference.BuildXmlElementReference();
                element.SourceContextReference.SourceContext = (XamlSourceContext)elementReference;
            }
            int start = this.writer.WriteBeginStartElement(element.Name.FullName);

            if (elementFormatting.AttributeLeadingWhitespace != null)
            {
                this.writer.SetWhitespace(elementFormatting.AttributeLeadingWhitespace);
            }
            string indent1 = indent + this.settings.IndentString;

            element.Attributes.EnsureOrdering();
            for (int index = 0; index < element.Attributes.Count; ++index)
            {
                this.WriteNode(indent1, element.Attributes[index]);
            }
            if (elementFormatting.AttributeTrailingWhitespace != null)
            {
                this.writer.SetWhitespace(elementFormatting.AttributeTrailingWhitespace);
            }
            int end;
            int length;

            if (element.Children.Count > 0)
            {
                bool flag = element.IsWhitespaceSignificant;
                for (int index = 0; index < element.Children.Count; ++index)
                {
                    switch (element.Children[index].NodeType)
                    {
                    case NodeType.Literal:
                    case NodeType.WhitespaceLiteral:
                        flag = true;
                        break;
                    }
                }
                this.writer.WriteEndStartElement();
                end = this.writer.Length;
                if (elementFormatting.ContentLeadingWhitespace != null)
                {
                    this.writer.SetWhitespace(elementFormatting.ContentLeadingWhitespace);
                }
                else
                {
                    this.writer.SetMinimumLineBreaks(elementSettings.LinesInside);
                }
                for (int index = 0; index < element.Children.Count; ++index)
                {
                    FormattedNode node = element.Children[index];
                    if (flag)
                    {
                        this.writer.SuppressWhitespace();
                    }
                    this.WriteNode(indent1, node);
                    if (flag)
                    {
                        this.writer.SuppressWhitespace();
                    }
                }
                if (elementFormatting.ContentTrailingWhitespace != null)
                {
                    this.writer.SetWhitespace(elementFormatting.ContentTrailingWhitespace);
                    if (element.IndentingBehavior == IndentingBehavior.FromContainer && this.writer.LineBreakCount > 0)
                    {
                        this.writer.SetIndent(indent);
                    }
                }
                else
                {
                    this.writer.SetMinimumLineBreaks(elementSettings.LinesInside);
                    this.writer.SetIndent(indent);
                }
                this.writer.WriteEndElement(true);
                length = this.writer.Length;
            }
            else
            {
                this.writer.WriteEndElement(false);
                end    = -1;
                length = this.writer.Length;
            }
            if (this.shouldUpdateSourceContext && elementReference != null)
            {
                elementReference.InitialTextSpan = (ITextRange) new TextRange(start, length);
                if (end != -1)
                {
                    elementReference.InitialStartTagSpan = (ITextRange) new TextRange(start, end);
                }
                element.SourceContextReference.SourceContext = (XamlSourceContext)elementReference;
            }
            if (elementFormatting.TrailingWhitespace != null)
            {
                this.writer.SetWhitespace(elementFormatting.TrailingWhitespace);
            }
            else
            {
                this.writer.SetMinimumLineBreaks(elementSettings.LinesOutside);
            }
        }