// --------------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // --------------------------------------------------------------------------- // --------------------------------------------------------------------- // // // --------------------------------------------------------------------- namespace Microsoft.Database.Isam { using System; using System.Collections; /// /// Enumerates the records visible to a given cursor. /// public class CursorEnumerator : IEnumerator { /// /// The cursor /// private Cursor cursor; /// /// The moved /// private bool moved = false; /// /// The current /// private bool current = false; /// /// Initializes a new instance of the class. /// /// The cursor. internal CursorEnumerator(Cursor cursor) { this.cursor = cursor; } /// /// Gets the current element in the collection. /// /// The current element in the collection. /// /// after last record in cursor /// or /// before first record in cursor /// /// /// This is the type safe version that may not work in other CLR /// languages. /// public FieldCollection Current { get { if (this.current == false) { if (this.moved == true) { throw new InvalidOperationException("after last record in cursor"); } else { throw new InvalidOperationException("before first record in cursor"); } } return this.cursor.Fields; } } /// /// Gets the current element in the collection. /// /// The current element in the collection. /// /// This is the standard version that will work with other CLR /// languages. /// object IEnumerator.Current { get { return this.Current; } } /// /// Sets the enumerator to its initial position, which is before the first element in the collection. /// public void Reset() { this.cursor.MoveBeforeFirst(); this.moved = false; this.current = false; } /// /// Advances the enumerator to the next element of the collection. /// /// /// true if the enumerator was successfully advanced to the next element; false if the enumerator has passed the end of the collection. /// public bool MoveNext() { if (this.moved == false) { this.Reset(); } this.current = this.cursor.MoveNext(); this.moved = true; return this.current; } } }