⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rowenumerator.cs

📁 微软的行业应用解决方案示例
💻 CS
字号:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Text;


namespace Microsoft.Mobile.Data
{
    /// <summary>
    /// Allows for simple iteration in a generic fashion over a collection of rows
    /// </summary>
    [SuppressMessage("Microsoft.Naming",
                     "CA1710:IdentifiersShouldHaveCorrectSuffix",
                     Justification = "More readable as RowEnumerator")]
    public abstract class RowEnumerator : IEnumerator<DataRow>, IEnumerable<DataRow>
    {
        #region Fields
        /// <summary>
        /// Used by implementations to set the current row.
        /// </summary>
        [SuppressMessage("Microsoft.Design", 
                         "CA1051:DoNotDeclareVisibleInstanceFields",
                         Justification="Done for performance reasons")]
        protected DataRow currentRow;
        #endregion


        #region Constructor(s) & Dispose
        /// <summary>
        /// Destructor for DataStore to only be used by Finalizer
        /// </summary>
        ~RowEnumerator()
        {
            Dispose(false);
        }

        /// <summary>
        /// Dispose of any resources associated with the RowEnumerator 
        /// implementation.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);

            // This object will be cleaned up by the Dispose method. Therefore, 
            // you should call GC.SupressFinalize to take this object off the 
            // finalization queue and prevent finalization code for this object
            // from executing a second time.
            GC.SuppressFinalize(this);
        }


        /// <summary>
        /// Actual dispose implementation. Used to prevent dispose executing 
        /// twice.
        /// </summary>
        /// <remarks>
        /// Dispose(bool disposing) executes in two distinct scenarios. If 
        /// disposing equals true, the method has been called directly or 
        /// indirectly by a user's code. Managed and unmanaged resources can be 
        /// disposed.
        /// 
        /// If disposing equals false, the method has been called by the 
        /// runtime from inside the finalizer and you should not reference 
        /// other objects. Only unmanaged resources can be disposed.
        /// </remarks>
        /// <param name="disposing">
        /// set to true when being called by dispose otherwise false.
        /// </param>
        protected abstract void Dispose(bool disposing);
        #endregion


        #region Properties
        /// <summary>
        /// Gets the <see cref="Microsoft.Mobile.Data.DataRow"/> in the collection 
        /// at the current position of the enumerator.
        /// </summary>
        /// <remarks>
        /// <para>Current is undefined under any of the following conditions:
        /// </para><list type="bullet">
        /// <item><description>
        /// The enumerator is positioned before the first element in the 
        /// collection, immediately after the enumerator is created. MoveNext 
        /// must be called to advance the enumerator to the first element of 
        /// the collection before reading the value of Current.
        /// </description></item>
        /// <item><description>
        /// The last call to MoveNext returned false, which indicates the end 
        /// of the collection.
        /// </description></item>
        /// <item><description>
        /// The enumerator is invalidated due to changes made in the 
        /// collection, such as adding, modifying, or deleting elements.
        /// </description></item>
        /// </list>
        /// <para>Current returns the same Row until MoveNext is called. 
        /// MoveNext sets Current to the next element.</para>
        /// </remarks>
        public DataRow Current
        {
            get
            {
                return currentRow;
            }
        }


        /// <summary>
        /// Required by .Net
        /// </summary>
        object IEnumerator.Current
        {
            get
            {
                return currentRow;
            }
        }
        #endregion


        #region Methods
        /// <summary>
        /// Returns the enumerator that iterates through the collection. It 
        /// allows for using foreach in code to loop through RowEnumerators.
        /// </summary>
        /// <returns>the RowEnumerator</returns>
        IEnumerator<DataRow> IEnumerable<DataRow>.GetEnumerator()
        {
            return this;
        }


        /// <summary>
        /// Returns the enumerator that iterates through the collection. It 
        /// allows for using foreach in code to loop through RowEnumerators.
        /// This is required by .Net and is not a mistake.
        /// </summary>
        /// <returns>the RowEnumerator</returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this;
        }


        /// <summary>
        /// Move to the next row if it is available.
        /// </summary>
        /// <returns>Return true if a row is available to be read</returns>
        public abstract bool MoveNext();

        /// <summary>
        /// Allows for resetting the enumeration back to the first row.
        /// </summary>
        public abstract void Reset();
        #endregion
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -