Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / XPath / Internal / DescendantBaseQuery.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="DescendantQuery.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
14     internal abstract class DescendantBaseQuery : BaseAxisQuery {
15         protected bool matchSelf;
16         protected bool abbrAxis;
17
18         public DescendantBaseQuery(Query qyParent, string Name, string Prefix, XPathNodeType Type, bool matchSelf, bool abbrAxis) : base(qyParent, Name, Prefix, Type)  {
19             this.matchSelf = matchSelf;
20             this.abbrAxis  = abbrAxis;
21         }
22         public DescendantBaseQuery(DescendantBaseQuery other) : base(other) {
23             this.matchSelf = other.matchSelf;
24             this.abbrAxis  = other.abbrAxis;
25         }
26
27         public override XPathNavigator MatchNode(XPathNavigator context) {
28             if (context != null) {
29                 if (!abbrAxis) {
30                     throw XPathException.Create(Res.Xp_InvalidPattern);
31                 }
32                 XPathNavigator result = null;
33                 if (matches(context)) {
34                     if (matchSelf) {
35                         if ((result = qyInput.MatchNode(context)) != null) {
36                             return result;
37                         }
38                     }
39
40                     XPathNavigator anc = context.Clone();
41                     while (anc.MoveToParent()) {
42                         if ((result = qyInput.MatchNode(anc)) != null) {
43                             return result;
44                         }
45                     }
46                 }
47             }
48             return null;
49         }
50
51         public override void PrintQuery(XmlWriter w) {
52             w.WriteStartElement(this.GetType().Name);
53             if (matchSelf) {
54                 w.WriteAttributeString("self", "yes");
55             }
56             if (NameTest) {
57                 w.WriteAttributeString("name", Prefix.Length != 0 ? Prefix + ':' + Name : Name);
58             }
59             if (TypeTest != XPathNodeType.Element) {
60                 w.WriteAttributeString("nodeType", TypeTest.ToString());
61             }
62             qyInput.PrintQuery(w);
63             w.WriteEndElement();
64         }
65     }
66 }