コード例 #1
0
 internal override void WriteContent(XmlWriter writer, WriteContext context)
 {
     MSBuildWhitespace.Write(StartInnerWhitespace, writer);
     if (rawValue != null)
     {
         if (!object.ReferenceEquals(rawValue, EmptyElementMarker))
         {
             if (rawValue.Length == 0 && !WasReadAsEmptyElement)
             {
                 writer.WriteString("");                          // Keep the non-empty element
             }
             else
             {
                 writer.WriteRaw(rawValue);
             }
         }
     }
     else if (textValue != null)
     {
         writer.WriteValue(textValue);
     }
     else
     {
         WriteValue(writer, context, unevaluatedValue);
     }
     MSBuildWhitespace.Write(EndInnerWhitespace, writer);
 }
コード例 #2
0
        internal virtual void WriteContent(XmlWriter writer, WriteContext context)
        {
            var children    = GetChildren();
            var hasChildren = children.Any();

            var hasContent = StartInnerWhitespace != null || EndInnerWhitespace != null;

            if (hasChildren || emptyElementMode == EmptyElementMode.NotEmpty || (emptyElementMode == EmptyElementMode.Unknown && !PreferEmptyElement))
            {
                MSBuildWhitespace.Write(StartInnerWhitespace, writer);

                foreach (var c in GetChildren())
                {
                    c.Write(writer, context);
                    hasContent = true;
                }

                MSBuildWhitespace.Write(EndInnerWhitespace, writer);
            }


            if (!hasContent && (emptyElementMode == EmptyElementMode.NotEmpty || (emptyElementMode == EmptyElementMode.Unknown && !PreferEmptyElement)))
            {
                // Don't write an empty element if it wasn't read as an empty element
                writer.WriteString("");
            }
        }
コード例 #3
0
        internal override void Write(XmlWriter writer, WriteContext context)
        {
            MSBuildWhitespace.Write(StartWhitespace, writer);

            writer.WriteStartElement(NamespacePrefix, GetElementName(), Namespace);

            if (unknownAttributes != null)
            {
                int    unknownIndex = 0;
                int    knownIndex   = 0;
                var    knownAtts    = attributeOrder ?? GetKnownAttributes();
                string lastAttr     = null;
                do
                {
                    if (unknownIndex < unknownAttributes.Length && (lastAttr == unknownAttributes [unknownIndex].AfterAttribute || unknownAttributes [unknownIndex].AfterAttribute == null))
                    {
                        var att = unknownAttributes [unknownIndex++];
                        writer.WriteAttributeString(att.Prefix, att.LocalName, att.Namespace, att.Value);
                        lastAttr = att.LocalName;
                    }
                    else if (knownIndex < knownAtts.Length)
                    {
                        var aname = knownAtts [knownIndex++];
                        lastAttr = aname;
                        var val = WriteAttribute(aname);
                        if (val != null)
                        {
                            writer.WriteAttributeString(aname, val);
                        }
                    }
                    else
                    {
                        lastAttr = null;
                    }
                } while (unknownIndex < unknownAttributes.Length || knownIndex < knownAtts.Length);
            }
            else
            {
                var knownAtts = attributeOrder ?? GetKnownAttributes();
                for (int i = 0; i < knownAtts.Length; i++)
                {
                    var aname = knownAtts [i];
                    var val   = WriteAttribute(aname);
                    if (val != null)
                    {
                        writer.WriteAttributeString(aname, val);
                    }
                }
            }

            WriteContent(writer, context);

            writer.WriteEndElement();

            MSBuildWhitespace.Write(EndWhitespace, writer);
        }
コード例 #4
0
ファイル: MSBuildProject.cs プロジェクト: sim756/monodevelop
        string SaveToString(WriteContext ctx)
        {
            // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the
            // XmlDocument will write the UTF8 header.
            ProjectWriter sw = new ProjectWriter(format.ByteOrderMark);

            sw.NewLine = format.NewLine;
            var xw = XmlWriter.Create(sw, new XmlWriterSettings {
                OmitXmlDeclaration = !hadXmlDeclaration,
                NewLineChars       = format.NewLine,
                NewLineHandling    = NewLineHandling.Replace
            });

            MSBuildWhitespace.Write(initialWhitespace, xw);

            Save(xw);

            xw.Dispose();

            return(sw.ToString());
        }
コード例 #5
0
        internal override void Write(XmlWriter writer, WriteContext context)
        {
            MSBuildWhitespace.Write(StartWhitespace, writer);

            writer.WriteStartElement(NamespacePrefix, GetElementName(), Namespace);

            var props = metadata.PropertiesAttributeOrder;

            if (props.Count > 0)
            {
                int    propIndex  = 0;
                int    knownIndex = 0;
                var    knownAtts  = attributeOrder ?? GetKnownAttributes();
                string lastAttr   = null;
                do
                {
                    if (propIndex < props.Count && (lastAttr == props [propIndex].AfterAttribute || props [propIndex].AfterAttribute == null))
                    {
                        var prop = props [propIndex++];
                        writer.WriteAttributeString(prop.Name, prop.Value);
                        lastAttr = prop.Name;
                    }
                    else if (knownIndex < knownAtts.Length)
                    {
                        var aname = knownAtts [knownIndex++];
                        lastAttr = aname;
                        var val = WriteAttribute(aname);
                        if (val != null)
                        {
                            writer.WriteAttributeString(aname, val);
                        }
                    }
                    else
                    {
                        lastAttr = null;
                    }
                } while (propIndex < props.Count || knownIndex < knownAtts.Length);
            }
            else
            {
                var knownAtts = attributeOrder ?? GetKnownAttributes();
                for (int i = 0; i < knownAtts.Length; i++)
                {
                    var aname = knownAtts [i];
                    var val   = WriteAttribute(aname);
                    if (val != null)
                    {
                        writer.WriteAttributeString(aname, val);
                    }
                }
            }

            WriteContent(writer, context);

            writer.WriteEndElement();

            MSBuildWhitespace.Write(EndWhitespace, writer);
            if (context.Evaluating)
            {
                string id = context.ItemMap.Count.ToString();
                context.ItemMap [id] = this;
            }
        }
コード例 #6
0
 internal override void Write(XmlWriter writer, WriteContext context)
 {
     MSBuildWhitespace.Write(StartWhitespace, writer);
     writer.WriteComment(Value);
     MSBuildWhitespace.Write(EndWhitespace, writer);
 }