Ejemplo n.º 1
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.º 2
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();
        }