using System;
using System.Collections;
using System.Collections.Generic;

namespace MrWu.core
{
    /// <summary>
    /// 
    /// </summary>
    public struct ArrayEnumerator<T> : IEnumerator<T>, IEnumerator
    {
        private T[] array;

        private int index;

        private T current;

        /// <summary>
        /// 迭代器
        /// </summary>
        /// <param name="array"></param>
        public ArrayEnumerator(T[] array) {
            this.array = array;
            index = 0;
            current = default(T);
        }

        /// <summary>
        /// 下一个
        /// </summary>
        /// <returns></returns>
        public bool MoveNext() {
            if (index < array.Length) {
                current = array[index];
                index++;
                return true;
            }
            return MoveNextRare();
        }

        private bool MoveNextRare() {
            index = array.Length + 1;
            return false;
        }

        /// <summary>
        /// 当前的值
        /// </summary>
        public T Current {
            get {
                return current;
            }
        }

        Object IEnumerator.Current {
            get {
                return Current;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public void Dispose() { }

        /// <summary>
        /// 重置
        /// </summary>
        public void Reset() {
            index = 0;
            current = default(T);
        }

    }
}
