Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / XPath / Internal / AttributeQuery.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="AttributeQuery.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 // <owner current="true" primary="true">Microsoft</owner>
6 //------------------------------------------------------------------------------
7
8 namespace MS.Internal.Xml.XPath {
9     using System;
10     using System.Xml;
11     using System.Xml.XPath;
12     using System.Diagnostics;
13     using System.Globalization;
14
15     internal sealed class AttributeQuery : BaseAxisQuery {
16         private bool onAttribute = false;
17
18         public AttributeQuery(Query qyParent, string Name, string Prefix, XPathNodeType Type) : base(qyParent, Name, Prefix, Type) {}
19         private AttributeQuery(AttributeQuery other) : base(other) {
20             this.onAttribute = other.onAttribute;
21         }
22         public override void Reset() {
23             onAttribute = false;
24             base.Reset();
25         }
26
27         public override XPathNavigator Advance() {
28             while (true) {
29                 if (! onAttribute) {
30                     currentNode = qyInput.Advance();
31                     if (currentNode == null) {
32                         return null;
33                     }
34                     position = 0;
35                     currentNode = currentNode.Clone();
36                     onAttribute = currentNode.MoveToFirstAttribute();
37                 } else {
38                     onAttribute = currentNode.MoveToNextAttribute();
39                 }
40
41                 if (onAttribute) {
42                     Debug.Assert(! currentNode.NamespaceURI.Equals(XmlReservedNs.NsXmlNs));
43                     if (matches(currentNode)) {
44                         position++;
45                         return currentNode;
46                     }
47                 }
48             } // while
49         }
50
51         public override XPathNavigator MatchNode(XPathNavigator context) {
52             if (context != null) {
53                 if (context.NodeType == XPathNodeType.Attribute && matches(context)) {
54                     XPathNavigator temp = context.Clone();
55                     if (temp.MoveToParent()) {
56                         return qyInput.MatchNode(temp);
57                     }
58                 }
59             }
60             return null;
61         }
62
63         public override XPathNodeIterator Clone() { return new AttributeQuery(this); }
64     }
65 }