예제 #1
0
        public override INodeSourceContext Clone(bool keepOldRanges)
        {
            XmlAttributeReference attributeReference = new XmlAttributeReference((XmlElementReference)this.Parent);

            this.CloneCopy((XamlSourceContext)attributeReference, keepOldRanges);
            return((INodeSourceContext)attributeReference);
        }
예제 #2
0
        public virtual XmlAttributeReference BuildXmlAttributeReference()
        {
            XmlAttributeReference attributeReference1 = this.SourceContext as XmlAttributeReference;
            XmlElementReference   parent = (XmlElementReference)null;

            if (this.documentNode != null)
            {
                for (DocumentNode documentNode = (DocumentNode)this.documentNode.Parent; documentNode != null && parent == null; documentNode = (DocumentNode)documentNode.Parent)
                {
                    parent = documentNode.SourceContext as XmlElementReference;
                }
            }
            XmlAttributeReference attributeReference2;

            if (attributeReference1 == null)
            {
                attributeReference2 = new XmlAttributeReference(parent);
            }
            else
            {
                attributeReference2        = (XmlAttributeReference)attributeReference1.Clone(false);
                attributeReference2.Parent = (XmlContainerReference)parent;
            }
            return(attributeReference2);
        }
        public override XmlAttributeReference BuildXmlAttributeReference()
        {
            XmlAttributeReference attributeReference = base.BuildXmlAttributeReference();

            if (this.attribute.SourceContext != null)
            {
                attributeReference.Parent = this.attribute.SourceContext.Parent;
            }
            return(attributeReference);
        }
 public RemovedXmlAttributeReference(XmlAttributeReference originalReference, bool isClone)
     : base((XmlElementReference)originalReference.Parent)
 {
     originalReference.CloneCopy((XamlSourceContext)this, false);
     this.textBuffer = originalReference.TextBuffer.Freeze();
     if (originalReference.TextRange != null)
     {
         this.TextRange = this.textBuffer.FreezeRange(originalReference.TextRange);
     }
     this.isCloned = isClone;
 }
예제 #5
0
        private void WriteAttribute(string indent, AttributeNode attribute)
        {
            XamlFormatter.XmlAttributeFormatting attributeFormatting = this.GetAttributeFormatting(attribute);
            if (attributeFormatting.LeadingWhitespace != null)
            {
                this.writer.SetWhitespace(attributeFormatting.LeadingWhitespace);
                if (attribute.IndentingBehavior == IndentingBehavior.FromContainer && this.writer.LineBreakCount > 0)
                {
                    this.writer.SetIndent(indent);
                }
            }
            else if (this.writer.LineBreakCount == 0 && string.IsNullOrEmpty(this.writer.Indent))
            {
                this.writer.SetIndent(this.settings.AttributeIndentString);
            }
            StringBuilder builder = new StringBuilder(attribute.Name.FullName);
            char          attributeQuoteCharacter;

            if (attributeFormatting.ValuePrefix != null)
            {
                attributeQuoteCharacter = attributeFormatting.AttributeQuoteCharacter;
                builder.Append(attributeFormatting.ValuePrefix);
            }
            else
            {
                attributeQuoteCharacter = this.settings.AttributeQuoteCharacter;
                builder.Append('=');
                builder.Append(attributeQuoteCharacter);
            }
            this.WriteAttributeValue(attributeQuoteCharacter, builder, attribute.Value, attribute.EscapeWhitespace);
            if (attributeFormatting.ValueSuffix != null)
            {
                builder.Append(attributeFormatting.ValueSuffix);
            }
            else
            {
                builder.Append(attributeQuoteCharacter);
            }
            int start  = this.writer.WriteAttribute(builder.ToString());
            int length = this.writer.Length;

            if (this.shouldUpdateSourceContext && attribute.SourceContextReference != null)
            {
                XmlAttributeReference attributeReference = attribute.SourceContextReference.BuildXmlAttributeReference();
                attributeReference.InitialTextSpan             = (ITextRange) new TextRange(start, length);
                attribute.SourceContextReference.SourceContext = (XamlSourceContext)attributeReference;
            }
            if (attributeFormatting.TrailingWhitespace == null)
            {
                return;
            }
            this.writer.SetWhitespace(attributeFormatting.TrailingWhitespace);
        }
예제 #6
0
        private XamlFormatter.XmlAttributeFormatting GetAttributeFormatting(AttributeNode attributeNode)
        {
            XamlFormatter.XmlAttributeFormatting attributeFormatting = new XamlFormatter.XmlAttributeFormatting();
            if (attributeNode.SourceContextReference == null)
            {
                return(attributeFormatting);
            }
            XmlAttributeReference attributeReference = attributeNode.SourceContextReference.SourceContext as XmlAttributeReference;

            if (attributeReference != null && attributeReference.TextRange != null)
            {
                string text = TextBufferHelper.GetHostBuffer(attributeReference.TextBuffer).GetText(attributeReference.TextRange.Offset, attributeReference.TextRange.Length);
                int    num  = text.IndexOf('=');
                if (num == -1)
                {
                    return(attributeFormatting);
                }
                int index1 = num - 1;
                while (index1 >= 0 && Scanner.IsXmlWhitespace(text[index1]))
                {
                    --index1;
                }
                int index2 = num + 1;
                while (index2 < text.Length && Scanner.IsXmlWhitespace(text[index2]))
                {
                    ++index2;
                }
                int startIndex = text.LastIndexOf(text[index2]);
                if (index2 >= 0 && startIndex > index2)
                {
                    attributeFormatting.LeadingWhitespace       = XamlFormatter.GetLeadingWhitespace((XamlSourceContext)attributeReference);
                    attributeFormatting.TrailingWhitespace      = XamlFormatter.GetTrailingWhitespace((XamlSourceContext)attributeReference);
                    attributeFormatting.ValuePrefix             = text.Substring(index1 + 1, index2 - index1);
                    attributeFormatting.ValueSuffix             = text.Substring(startIndex, 1);
                    attributeFormatting.AttributeQuoteCharacter = text[index2];
                }
            }
            return(attributeFormatting);
        }