Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / System.Xml / System / Xml / XPath / XPathExpr.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="XPathExpr.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 System.Xml.XPath {
9
10     using System;
11     using System.Xml;
12     using System.Collections;
13     using MS.Internal.Xml.XPath;
14
15     public enum XmlSortOrder {
16         Ascending       = 1,
17         Descending      = 2,
18     }
19
20     public enum XmlCaseOrder {
21         None            = 0,
22         UpperFirst      = 1,
23         LowerFirst      = 2,
24     }
25
26     public enum XmlDataType {
27         Text            = 1,
28         Number          = 2,
29     }
30
31     public enum XPathResultType {
32         Number         = 0 ,
33         String          = 1,
34         Boolean         = 2,
35         NodeSet        = 3,
36         Navigator       = XPathResultType.String,
37         Any            = 5,
38         Error
39     };
40
41     public abstract class XPathExpression {
42         internal XPathExpression(){}
43
44         public  abstract string Expression { get; }
45
46         public abstract void AddSort(object expr, IComparer comparer);
47
48         public abstract void AddSort(object expr, XmlSortOrder order, XmlCaseOrder caseOrder, string lang, XmlDataType dataType);
49
50         public abstract XPathExpression Clone();
51
52         public abstract void SetContext(XmlNamespaceManager nsManager);
53
54         public abstract void SetContext(IXmlNamespaceResolver nsResolver);
55
56         public abstract XPathResultType ReturnType { get; }
57         
58         public static XPathExpression Compile(string xpath) {
59             return Compile(xpath, /*nsResolver:*/null);
60         }
61
62         public static XPathExpression Compile(string xpath, IXmlNamespaceResolver nsResolver) {
63             bool hasPrefix;
64             Query query = new QueryBuilder().Build(xpath, out hasPrefix);
65             CompiledXpathExpr expr = new CompiledXpathExpr(query, xpath, hasPrefix);
66             if (null != nsResolver) {
67                 expr.SetContext(nsResolver);
68             }
69             return expr;
70         }
71
72         private void PrintQuery(XmlWriter w) {
73             ((CompiledXpathExpr)this).QueryTree.PrintQuery(w);
74         }
75     }
76 }