Пример #1
0
 internal void AddChildValue(XmlElementValue value)
 {
     if (this.childValues == null)
     {
         this.childValues = new List <XmlElementValue>();
     }
     this.childValues.Add(value);
 }
Пример #2
0
 internal static IEnumerable <XmlElementValue <T> > OfResultType <T>(this IEnumerable <XmlElementValue> elements)
     where T : class
 {
     foreach (var element in elements)
     {
         XmlElementValue <T> result = element as XmlElementValue <T>;
         if (result != null)
         {
             yield return(result);
         }
         else if (element.UntypedValue is T)
         {
             yield return(new XmlElementValue <T>(element.Name, element.Location, element.ValueAs <T>()));
         }
     }
 }
Пример #3
0
 internal static IEnumerable <XmlElementValue <T> > OfResultType <T>(this IEnumerable <XmlElementValue> elements)
     where T : class
 {
     foreach (XmlElementValue xmlElementValue in elements)
     {
         XmlElementValue <T> xmlElementValue1 = xmlElementValue as XmlElementValue <T>;
         if (xmlElementValue1 == null)
         {
             if (xmlElementValue.UntypedValue as T == null)
             {
                 continue;
             }
             yield return(new XmlElementValue <T>(xmlElementValue.Name, xmlElementValue.Location, xmlElementValue.ValueAs <T>()));
         }
         else
         {
             yield return(xmlElementValue1);
         }
     }
 }
Пример #4
0
        private void EndElement()
        {
            XmlTextValue xmlTextValue;

            XmlDocumentParser.ElementScope elementScope;
            XmlDocumentParser.ElementScope elementScope1 = this.currentBranch.Pop();
            XmlDocumentParser xmlDocumentParser          = this;

            if (this.currentBranch.Count > 0)
            {
                elementScope = this.currentBranch.Peek();
            }
            else
            {
                elementScope = null;
            }
            xmlDocumentParser.currentScope = elementScope;
            XmlElementParser parser          = elementScope1.Parser;
            XmlElementValue  xmlElementValue = parser.Parse(elementScope1.Element, elementScope1.ChildValues);

            if (xmlElementValue != null)
            {
                if (this.currentScope == null)
                {
                    this.Result = xmlElementValue;
                }
                else
                {
                    this.currentScope.AddChildValue(xmlElementValue);
                }
            }
            foreach (XmlAttributeInfo unused in elementScope1.Element.Attributes.Unused)
            {
                this.ReportUnexpectedAttribute(unused.Location, unused.Name);
            }
            IList <XmlElementValue>       childValues       = elementScope1.ChildValues;
            IEnumerable <XmlElementValue> xmlElementValues  = childValues.Where <XmlElementValue>((XmlElementValue v) => v.IsText);
            IEnumerable <XmlElementValue> xmlElementValues1 = xmlElementValues;
            IEnumerable <XmlElementValue> xmlElementValues2 = xmlElementValues1.Where <XmlElementValue>((XmlElementValue t) => !t.IsUsed);

            if (xmlElementValues2.Any <XmlElementValue>())
            {
                if (xmlElementValues2.Count <XmlElementValue>() != xmlElementValues.Count <XmlElementValue>())
                {
                    xmlTextValue = (XmlTextValue)xmlElementValues2.First <XmlElementValue>();
                }
                else
                {
                    xmlTextValue = (XmlTextValue)xmlElementValues.First <XmlElementValue>();
                }
                this.ReportTextNotAllowed(xmlTextValue.Location, xmlTextValue.Value);
            }
            IList <XmlElementValue> childValues1 = elementScope1.ChildValues;

            foreach (XmlElementValue xmlElementValue1 in childValues1.Where <XmlElementValue>((XmlElementValue v) => {
                if (v.IsText)
                {
                    return(false);
                }
                else
                {
                    return(!v.IsUsed);
                }
            }
                                                                                              ))
            {
                this.ReportUnusedElement(xmlElementValue1.Location, xmlElementValue1.Name);
            }
        }
Пример #5
0
        private void EndElement()
        {
            ElementScope scope = this.currentBranch.Pop();

            this.currentScope = this.currentBranch.Count > 0 ? this.currentBranch.Peek() : null;

            XmlElementParser parser      = scope.Parser;
            XmlElementValue  resultValue = parser.Parse(scope.Element, scope.ChildValues);

            if (resultValue != null)
            {
                if (this.currentScope != null)
                {
                    this.currentScope.AddChildValue(resultValue);
                }
                else
                {
                    this.Result = resultValue;
                }
            }

            foreach (var unused in scope.Element.Attributes.Unused)
            {
                // there's no handler for (namespace,name) and there wasn't a validation error.
                // Report an error of our own if the node is in no namespace or if it is in one of our xml schemas target namespace.
                this.ReportUnexpectedAttribute(unused.Location, unused.Name);
            }

            // For text nodes, one may be expected but additional text should cause an error.
            var textNodes  = scope.ChildValues.Where(v => v.IsText);
            var unusedText = textNodes.Where(t => !t.IsUsed);

            if (unusedText.Any())
            {
                XmlTextValue firstInvalidText;
                if (unusedText.Count() == textNodes.Count())
                {
                    // Text is not expected at all for this element
                    firstInvalidText = (XmlTextValue)textNodes.First();
                }
                else
                {
                    // Additional text was unexpected
                    firstInvalidText = (XmlTextValue)unusedText.First();
                }

                this.ReportTextNotAllowed(firstInvalidText.Location, firstInvalidText.Value);
            }

            // If any elements were unused, the csdl is not properly formed. This could be a result of an entirely unexpected element
            // or, it could be an expected but superfluous element.
            // Consider:
            // <ReferentialConstraint>
            //     <Principal>... </Principal>
            //     <Dependent>... </Dependent>
            //     <Principal>... </Principal>
            // </ReferentialConstraint>
            //
            // The second occurrence of 'Principal' will be successfully parsed, but the element parser for ReferentialConstraint will not use its value because only the first occurence is expected.
            // This will also catch if only a single type reference (Row, Collection, EntityReference) element was expected but multiple are provided
            foreach (var unusedChildValue in scope.ChildValues.Where(v => !v.IsText && !v.IsUsed))
            {
                this.ReportUnusedElement(unusedChildValue.Location, unusedChildValue.Name);
            }
        }