The Labs \ Source Viewer \ SSCLI \ System.Xml.Xsl.Runtime \ IdIterator

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlIterators.cs" company="Microsoft">
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. // </copyright>
  14. //------------------------------------------------------------------------------
  15. using System;
  16. using System.Xml;
  17. using System.Xml.XPath;
  18. using System.ComponentModel;
  19. namespace System.Xml.Xsl.Runtime
  20. {
  21.    
  22.     /// <summary>
  23.     /// Iterators that use containment to control a nested iterator return one of the following values from MoveNext().
  24.     /// </summary>
  25.     [EditorBrowsable(EditorBrowsableState.Never)]
  26.     public enum IteratorResult
  27.     {
  28.         NoMoreNodes,
  29.         // Iteration is complete; there are no more nodes
  30.         NeedInputNode,
  31.         // The next node needs to be fetched from the contained iterator before iteration can continue
  32.         HaveCurrentNode
  33.         // This iterator's Current property is set to the next node in the iteration
  34.     }
  35.    
  36.    
  37.     /// <summary>
  38.     /// Tokenize a string containing IDREF values and deref the values in order to get a list of ID elements.
  39.     /// </summary>
  40.     [EditorBrowsable(EditorBrowsableState.Never)]
  41.     public struct IdIterator
  42.     {
  43.         private XPathNavigator navCurrent;
  44.         private string[] idrefs;
  45.         private int idx;
  46.        
  47.         public void Create(XPathNavigator context, string value)
  48.         {
  49.             this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, context);
  50.             this.idrefs = XmlConvert.SplitString(value);
  51.             this.idx = -1;
  52.         }
  53.        
  54.         public bool MoveNext()
  55.         {
  56.             do {
  57.                 this.idx++;
  58.                 if (this.idx >= idrefs.Length)
  59.                     return false;
  60.             }
  61.             while (!this.navCurrent.MoveToId(this.idrefs[this.idx]));
  62.            
  63.             return true;
  64.         }
  65.        
  66.         /// <summary>
  67.         /// Return the current result navigator. This is only defined after MoveNext() has returned true.
  68.         /// </summary>
  69.         public XPathNavigator Current {
  70.             get { return this.navCurrent; }
  71.         }
  72.     }
  73. }

Developer Fusion