1 //------------------------------------------------------------------------------
2 // <copyright file="IDQuery.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 // <owner current="true" primary="true">[....]</owner>
6 //------------------------------------------------------------------------------
8 namespace MS.Internal.Xml.XPath {
11 using System.Xml.XPath;
13 using System.Diagnostics;
14 using System.Collections.Generic;
16 internal sealed class IDQuery : CacheOutputQuery {
18 public IDQuery(Query arg) : base(arg) {}
19 private IDQuery(IDQuery other) : base(other) { }
21 public override object Evaluate(XPathNodeIterator context) {
22 object argVal = base.Evaluate(context);
23 XPathNavigator contextNode = context.Current.Clone();
25 switch (GetXPathType(argVal)) {
26 case XPathResultType.NodeSet:
28 while ((temp = input.Advance()) != null) {
29 ProcessIds(contextNode, temp.Value);
32 case XPathResultType.String:
33 ProcessIds(contextNode, (string)argVal);
35 case XPathResultType.Number:
36 ProcessIds(contextNode, StringFunctions.toString((double)argVal));
38 case XPathResultType.Boolean:
39 ProcessIds(contextNode, StringFunctions.toString((bool)argVal));
41 case XPathResultType_Navigator:
42 ProcessIds(contextNode, ((XPathNavigator)argVal).Value);
48 void ProcessIds(XPathNavigator contextNode, string val) {
49 string[] ids = XmlConvert.SplitString(val);
50 for (int idx = 0; idx < ids.Length; idx++) {
51 if (contextNode.MoveToId(ids[idx])) {
52 Insert(outputBuffer, contextNode);
57 public override XPathNavigator MatchNode(XPathNavigator context) {
58 Evaluate(new XPathSingletonIterator(context, /*moved:*/true));
59 XPathNavigator result;
60 while ((result = Advance()) != null) {
61 if (result.IsSamePosition(context)) {
68 public override XPathNodeIterator Clone() { return new IDQuery(this); }