The Labs \ Source Viewer \ SSCLI \ System.Xml \ XmlChildEnumerator

  1. //------------------------------------------------------------------------------
  2. // <copyright file="XmlChildEnumerator.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. namespace System.Xml
  16. {
  17.     using System.Collections;
  18.    
  19.     internal sealed class XmlChildEnumerator : IEnumerator
  20.     {
  21.         internal XmlNode container;
  22.         internal XmlNode child;
  23.         internal bool isFirst;
  24.        
  25.         internal XmlChildEnumerator(XmlNode container)
  26.         {
  27.             this.container = container;
  28.             this.child = container.FirstChild;
  29.             this.isFirst = true;
  30.         }
  31.        
  32.         bool IEnumerator.MoveNext()
  33.         {
  34.             return this.MoveNext();
  35.         }
  36.        
  37.         internal bool MoveNext()
  38.         {
  39.             if (isFirst) {
  40.                 child = container.FirstChild;
  41.                 isFirst = false;
  42.             }
  43.             else if (child != null) {
  44.                 child = child.NextSibling;
  45.             }
  46.            
  47.             return child != null;
  48.         }
  49.        
  50.         void IEnumerator.Reset()
  51.         {
  52.             isFirst = true;
  53.             child = container.FirstChild;
  54.         }
  55.        
  56.         object IEnumerator.Current {
  57.             get { return this.Current; }
  58.         }
  59.        
  60.         internal XmlNode Current {
  61.             get {
  62.                 if (isFirst || child == null)
  63.                     throw new InvalidOperationException(Res.GetString(Res.Xml_InvalidOperation));
  64.                
  65.                 return child;
  66.             }
  67.         }
  68.     }
  69. }

Developer Fusion