File: FrameworkFork\Microsoft.Xml\Xml\XPath\Internal\XPathSelectionIterator.cs
Web Access
Project: src\src\dotnet-svcutil\lib\src\dotnet-svcutil-lib.csproj (dotnet-svcutil-lib)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
 
namespace MS.Internal.Xml.XPath
{
    using System;
    using Microsoft.Xml;
    using Microsoft.Xml.XPath;
    using System.Diagnostics;
    using System.Globalization;
 
    // We need this wrapper object to:
    //      1. Calculate position
    //      2. Protect internal query.Current from user who may call MoveNext().
    internal class XPathSelectionIterator : ResetableIterator
    {
        private XPathNavigator _nav;
        private Query _query;
        private int _position;
 
        internal XPathSelectionIterator(XPathNavigator nav, Query query)
        {
            _nav = nav.Clone();
            _query = query;
        }
 
        protected XPathSelectionIterator(XPathSelectionIterator it)
        {
            _nav = it._nav.Clone();
            _query = (Query)it._query.Clone();
            _position = it._position;
        }
 
        public override void Reset()
        {
            _query.Reset();
        }
 
        public override bool MoveNext()
        {
            XPathNavigator n = _query.Advance();
            if (n != null)
            {
                _position++;
                if (!_nav.MoveTo(n))
                {
                    _nav = n.Clone();
                }
                return true;
            }
            return false;
        }
 
        public override int Count { get { return _query.Count; } }
        public override XPathNavigator Current { get { return _nav; } }
        public override int CurrentPosition { get { return _position; } }
        public override XPathNodeIterator Clone() { return new XPathSelectionIterator(this); }
    }
}