Ejemplo n.º 1
0
        internal override void Read(MSBuildXmlReader reader)
        {
            StartWhitespace = reader.ConsumeWhitespace();
            Value           = reader.Value;
            reader.Read();

            while (reader.IsWhitespace)
            {
                reader.ReadAndStoreWhitespace();
            }

            EndWhitespace = reader.ConsumeWhitespaceUntilNewLine();
        }
Ejemplo n.º 2
0
		internal override void Read (MSBuildXmlReader reader)
		{
			if (reader.ForEvaluation) {
				if (reader.MoveToFirstAttribute ()) {
					do {
						ReadAttribute (reader.LocalName, reader.Value);
					} while (reader.MoveToNextAttribute ());
				}
			} else {
				StartWhitespace = reader.ConsumeWhitespace ();

				if (reader.MoveToFirstAttribute ()) {
					var knownAtts = GetKnownAttributes ();
					int attOrderIndex = 0;
					int expectedKnownAttIndex = 0;
					bool attOrderIsUnexpected = false;
					List<UnknownAttribute> unknownAttsList = null;
					attributeOrder = new string [knownAtts.Length];
					string lastAttr = null;
					do {
						var attName = reader.LocalName;
						int i = Array.IndexOf (knownAtts, attName);
						if (i == -1) {
							if (attName == "xmlns")
								continue;
							
							#if ATTR_STATS
							UnknownAtts.Add (GetType ().Name + " " + attName);
							#endif

							var ua = new UnknownAttribute {
								LocalName = attName,
								Prefix = !string.IsNullOrEmpty (reader.Prefix) ? reader.Prefix : null,
								Namespace = reader.NamespaceURI,
								Value = reader.Value,
								AfterAttribute = lastAttr
							};
							if (unknownAttsList == null)
								unknownAttsList = new List<UnknownAttribute> ();
							unknownAttsList.Add (ua);
							lastAttr = null;
						} else {
							if (attOrderIndex >= attributeOrder.Length)
								throw new InvalidOperationException ("Attribute specified twice");
							attributeOrder [attOrderIndex++] = attName;
							ReadAttribute (attName, reader.Value);
							if (i < expectedKnownAttIndex) {
								// Attributes have an unexpected order
								attOrderIsUnexpected = true;
							}
							expectedKnownAttIndex = i + 1;
							lastAttr = attName;
						}
					} while (reader.MoveToNextAttribute ());

					if (unknownAttsList != null)
						unknownAttributes = unknownAttsList.ToArray ();
					if (!attOrderIsUnexpected)
						attributeOrder = null;
					else {
						// Fill the remaning slots in the attributeOrder array (known attributes that were not read)
						foreach (var a in knownAtts) {
							if (!attributeOrder.Contains (a)) {
								if (attOrderIndex >= attributeOrder.Length)
									throw new InvalidOperationException ("Attribute specified twice");
								attributeOrder [attOrderIndex++] = a;
							}
						}
					}

					#if ATTR_STATS
					var atts = GetType().Name + " - " + string.Join (", ", (attributeOrder ?? knownAtts));
					if (attributeOrder == null)
						atts += " *";
					KnownAttOrder.Add (atts);
					#endif
				}
			}
			reader.MoveToElement ();

			emptyElementMode = reader.IsEmptyElement ? EmptyElementMode.Empty : EmptyElementMode.NotEmpty;

			if (!string.IsNullOrEmpty (reader.Prefix) && !SupportsNamespacePrefixes)
				throw new MSBuildFileFormatException ("XML namespace prefixes are not supported for " + reader.LocalName + " elements");

			ReadContent (reader);

			while (reader.IsWhitespace)
				reader.ReadAndStoreWhitespace ();

			EndWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
		}
Ejemplo n.º 3
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 ();
		}
Ejemplo n.º 4
0
        internal override void Read(MSBuildXmlReader reader)
        {
            if (reader.ForEvaluation && !ContentRequiredForEvaluation)
            {
                if (reader.MoveToFirstAttribute())
                {
                    do
                    {
                        ReadAttribute(reader.LocalName, reader.Value);
                    } while (reader.MoveToNextAttribute());
                }
            }
            else
            {
                StartWhitespace = reader.ConsumeWhitespace();

                if (reader.MoveToFirstAttribute())
                {
                    var  knownAtts             = GetKnownAttributes();
                    int  attOrderIndex         = 0;
                    int  expectedKnownAttIndex = 0;
                    bool attOrderIsUnexpected  = false;
                    List <UnknownAttribute> unknownAttsList = null;
                    attributeOrder = new string [knownAtts.Length];
                    string lastAttr = null;
                    do
                    {
                        var attName = reader.LocalName;
                        int i       = Array.IndexOf(knownAtts, attName);
                        if (i == -1)
                        {
                            if (attName == "xmlns")
                            {
                                continue;
                            }

                                                        #if ATTR_STATS
                            UnknownAtts.Add(GetType().Name + " " + attName);
                                                        #endif

                            var ua = new UnknownAttribute {
                                LocalName      = attName,
                                Prefix         = !string.IsNullOrEmpty(reader.Prefix) ? reader.Prefix : null,
                                Namespace      = reader.NamespaceURI,
                                Value          = reader.Value,
                                AfterAttribute = lastAttr
                            };
                            if (unknownAttsList == null)
                            {
                                unknownAttsList = new List <UnknownAttribute> ();
                            }
                            unknownAttsList.Add(ua);
                            lastAttr = null;
                        }
                        else
                        {
                            if (attOrderIndex >= attributeOrder.Length)
                            {
                                throw new InvalidOperationException("Attribute specified twice");
                            }
                            attributeOrder [attOrderIndex++] = attName;
                            ReadAttribute(attName, reader.Value);
                            if (i < expectedKnownAttIndex)
                            {
                                // Attributes have an unexpected order
                                attOrderIsUnexpected = true;
                            }
                            expectedKnownAttIndex = i + 1;
                            lastAttr = attName;
                        }
                    } while (reader.MoveToNextAttribute());

                    if (unknownAttsList != null)
                    {
                        unknownAttributes = unknownAttsList.ToArray();
                    }
                    if (!attOrderIsUnexpected)
                    {
                        attributeOrder = null;
                    }
                    else
                    {
                        // Fill the remaning slots in the attributeOrder array (known attributes that were not read)
                        foreach (var a in knownAtts)
                        {
                            if (!attributeOrder.Contains(a))
                            {
                                if (attOrderIndex >= attributeOrder.Length)
                                {
                                    throw new InvalidOperationException("Attribute specified twice");
                                }
                                attributeOrder [attOrderIndex++] = a;
                            }
                        }
                    }

                                        #if ATTR_STATS
                    var atts = GetType().Name + " - " + string.Join(", ", (attributeOrder ?? knownAtts));
                    if (attributeOrder == null)
                    {
                        atts += " *";
                    }
                    KnownAttOrder.Add(atts);
                                        #endif
                }
            }
            reader.MoveToElement();

            emptyElementMode = reader.IsEmptyElement ? EmptyElementMode.Empty : EmptyElementMode.NotEmpty;

            if (!string.IsNullOrEmpty(reader.Prefix) && !SupportsNamespacePrefixes)
            {
                throw new MSBuildFileFormatException("XML namespace prefixes are not supported for " + reader.LocalName + " elements");
            }

            ReadContent(reader);

            while (reader.IsWhitespace)
            {
                reader.ReadAndStoreWhitespace();
            }

            EndWhitespace = reader.ConsumeWhitespaceUntilNewLine();
        }
Ejemplo n.º 5
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();
        }
		internal override void Read (MSBuildXmlReader reader)
		{
			StartWhitespace = reader.ConsumeWhitespace ();
			Value = reader.Value;
			reader.Read ();

			while (reader.IsWhitespace)
				reader.ReadAndStoreWhitespace ();

			EndWhitespace = reader.ConsumeWhitespaceUntilNewLine ();
		}