string ReadValue(MSBuildXmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                rawValue = EmptyElementMarker;
                reader.Skip();
                return(string.Empty);
            }

            MSBuildXmlElement elem = new MSBuildXmlElement();

            elem.ParentNode = this;
            elem.ReadContent(reader);

            if (elem.ChildNodes.Count == 0)
            {
                StartInnerWhitespace = elem.StartInnerWhitespace;
                EndInnerWhitespace   = elem.EndInnerWhitespace;
                rawValue             = elem.GetInnerXml();
                return(string.Empty);
            }

            if (elem.ChildNodes.Count == 1)
            {
                var node = elem.ChildNodes [0] as MSBuildXmlValueNode;
                if (node != null)
                {
                    StartInnerWhitespace = elem.StartInnerWhitespace;
                    StartInnerWhitespace = MSBuildWhitespace.AppendSpace(StartInnerWhitespace, node.StartWhitespace);
                    EndInnerWhitespace   = node.EndWhitespace;
                    EndInnerWhitespace   = MSBuildWhitespace.AppendSpace(EndInnerWhitespace, elem.EndInnerWhitespace);
                    if (node is MSBuildXmlTextNode)
                    {
                        textValue = node.Value;
                        return(node.Value.Trim());
                    }
                    else if (node is MSBuildXmlCDataNode)
                    {
                        rawValue = "<![CDATA[" + node.Value + "]]>";
                        return(node.Value);
                    }
                }
            }

            if (elem.ChildNodes.Any(n => n is MSBuildXmlElement))
            {
                return(elem.GetInnerXml());
            }
            else
            {
                rawValue = elem.GetInnerXml();
                return(elem.GetText());
            }
        }
Exemple #2
0
 internal virtual void ReadChildElement(MSBuildXmlReader reader)
 {
     if (reader.ForEvaluation && !ContentRequiredForEvaluation)
     {
         reader.Skip();
     }
     else
     {
         var n = new MSBuildXmlElement();
         n.Read(reader);
         n.ParentNode = this;
         ChildNodes   = ChildNodes.Add(n);
     }
 }
		internal virtual void ReadChildElement (MSBuildXmlReader reader)
		{
			if (reader.ForEvaluation)
				reader.Skip ();
			else {
				var n = new MSBuildXmlElement ();
				n.Read (reader);
				n.ParentNode = this;
				ChildNodes = ChildNodes.Add (n);
			}
		}
		internal virtual void ReadContent (MSBuildXmlReader reader)
		{
			if (reader.IsEmptyElement) {
				reader.Skip ();
				return;
			}
			var elemName = reader.LocalName;

			reader.Read ();
			bool childFound = false;

			while (reader.NodeType != XmlNodeType.EndElement) {
				if (reader.NodeType == XmlNodeType.Element) {
					if (!childFound) {
						childFound = true;
						StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
					}
					ReadChildElement (reader);
				} else if (reader.NodeType == XmlNodeType.Text) {
					if (!SupportsTextContent)
						throw new MSBuildFileFormatException ("Text content is not allowed inside a " + elemName + " element");
					if (!childFound) {
						childFound = true;
						StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
					}
					var tn = new MSBuildXmlTextNode ();
					tn.Read (reader);
					ChildNodes = ChildNodes.Add (tn);
				} else if (reader.NodeType == XmlNodeType.CDATA) {
					if (!childFound) {
						childFound = true;
						StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
					}
					var tn = new MSBuildXmlCDataNode ();
					tn.Read (reader);
					ChildNodes = ChildNodes.Add (tn);
				} else if (reader.NodeType == XmlNodeType.Comment) {
					if (!childFound) {
						childFound = true;
						StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
					}
					var tn = new MSBuildXmlCommentNode ();
					tn.Read (reader);
					ChildNodes = ChildNodes.Add (tn);
				} else if (reader.IsWhitespace) {
					reader.ReadAndStoreWhitespace ();
				} else if (reader.EOF)
					throw new InvalidOperationException ("Invalid XML");
				else
					reader.Read ();
			}
			reader.Read ();

			EndInnerWhitespace = reader.ConsumeWhitespace ();
		}
		string ReadValue (MSBuildXmlReader reader)
		{
			if (reader.IsEmptyElement) {
				rawValue = EmptyElementMarker;
				reader.Skip ();
				return string.Empty;
			}

			MSBuildXmlElement elem = new MSBuildXmlElement ();
			elem.ParentNode = this;
			elem.ReadContent (reader);

			if (elem.ChildNodes.Count == 0) {
				StartInnerWhitespace = elem.StartInnerWhitespace;
				EndInnerWhitespace = elem.EndInnerWhitespace;
				rawValue = elem.GetInnerXml ();
				return string.Empty;
			}

			if (elem.ChildNodes.Count == 1) {
				var node = elem.ChildNodes [0] as MSBuildXmlValueNode;
				if (node != null) {
					StartInnerWhitespace = elem.StartInnerWhitespace;
					StartInnerWhitespace = MSBuildWhitespace.AppendSpace (StartInnerWhitespace, node.StartWhitespace);
					EndInnerWhitespace = node.EndWhitespace;
					EndInnerWhitespace = MSBuildWhitespace.AppendSpace (EndInnerWhitespace, elem.EndInnerWhitespace);
					if (node is MSBuildXmlTextNode) {
						textValue = node.Value;
						return node.Value.Trim ();
					} else if (node is MSBuildXmlCDataNode) {
						rawValue = "<![CDATA[" + node.Value + "]]>";
						return node.Value;
					}
				}
			}

			if (elem.ChildNodes.Any (n => n is MSBuildXmlElement))
				return elem.GetInnerXml ();
			else {
				rawValue = elem.GetInnerXml ();
				return elem.GetText ();
			}
		}
Exemple #6
0
        internal virtual void ReadContent(MSBuildXmlReader reader)
        {
            if (reader.IsEmptyElement)
            {
                reader.Skip();
                return;
            }
            var elemName = reader.LocalName;

            reader.Read();
            bool childFound = false;

            while (reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (!childFound)
                    {
                        childFound           = true;
                        StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine();
                    }
                    ReadChildElement(reader);
                }
                else if (reader.NodeType == XmlNodeType.Text)
                {
                    if (!SupportsTextContent)
                    {
                        throw new MSBuildFileFormatException("Text content is not allowed inside a " + elemName + " element");
                    }
                    if (!childFound)
                    {
                        childFound           = true;
                        StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine();
                    }
                    var tn = new MSBuildXmlTextNode();
                    tn.Read(reader);
                    ChildNodes = ChildNodes.Add(tn);
                }
                else if (reader.NodeType == XmlNodeType.CDATA)
                {
                    if (!childFound)
                    {
                        childFound           = true;
                        StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine();
                    }
                    var tn = new MSBuildXmlCDataNode();
                    tn.Read(reader);
                    ChildNodes = ChildNodes.Add(tn);
                }
                else if (reader.NodeType == XmlNodeType.Comment)
                {
                    if (!childFound)
                    {
                        childFound           = true;
                        StartInnerWhitespace = reader.ConsumeWhitespaceUntilNewLine();
                    }
                    var tn = new MSBuildXmlCommentNode();
                    tn.Read(reader);
                    ChildNodes = ChildNodes.Add(tn);
                }
                else if (reader.IsWhitespace)
                {
                    reader.ReadAndStoreWhitespace();
                }
                else if (reader.EOF)
                {
                    throw new InvalidOperationException("Invalid XML");
                }
                else
                {
                    reader.Read();
                }
            }
            reader.Read();

            EndInnerWhitespace = reader.ConsumeWhitespace();
        }