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

namespace Hydra.Framework.Collections
{
    /// <summary>
    /// Wrap an enumerable so that clients can't get to the underlying 
    /// implementation via a down-cast.
    /// </summary>
    [Serializable]
    internal class WrapEnumerable<T>
        : IEnumerable<T>
    {
        #region Member Variables
        /// <summary>
        /// Wrapped Enumeration Type T
        /// </summary>
        private IEnumerable<T> wrapped;
        #endregion

        #region Constructors
        /// <summary>
        /// Create the wrapper around an enumerable.
        /// </summary>
        /// <param name="wrapped">IEnumerable to wrap.</param>
        public WrapEnumerable(IEnumerable<T> wrapped)
        {
            this.wrapped = wrapped;
        }
        #endregion

        #region IEnumerable Implementation
        /// <summary>
        /// Gets the enumerator.
        /// </summary>
        /// <returns></returns>
        public IEnumerator<T> GetEnumerator()
        {
            return wrapped.GetEnumerator();
        }

        /// <summary>
        /// Returns an enumerator that iterates through a collection.
        /// </summary>
        /// <returns>
        /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
        /// </returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return ((IEnumerable)wrapped).GetEnumerator();
        }
        #endregion
    }

}