BindableArrayList.cst

来源:互联网 发布:突击英雄知乎 编辑:程序博客网 时间:2024/06/05 20:28

<%@ CodeTemplate Language="C#" TargetLanguage="C#" Description="Generates a strongly typed ArrayList collection." Debug="True" %>
<%@ Property Name="Accessibility" Type="AccessibilityEnum" Category="Options" Description="The accessibility of the collection class." %>
<%@ Property Name="TargetNamespace" Type="System.String" Optional="True" Category="Namespaces" Description="The namespace of the collection class." %>
<%@ Property Name="ClassName" Type="System.String" Optional="True" Category="Context" Description="The name of the collection class." %>
<%@ Property Name="ItemType" Type="System.String" Category="Context" Description="The element type of the collection." %>
<%@ Property Name="ItemNamespace" Type="System.String" Optional="True" Category="Namespaces" Description="The namespace of the element type." %>
<%@ Property Name="ItemValueType" Type="System.Boolean" Category="Context" Default="false" Description="Indicates whether ItemType is a value type." %>
<%@ Property Name="ItemCustomSearch" Type="System.Boolean" Category="Options" Default="false" Description="Use custom search routines for ItemType." %>
<%@ Property Name="DeepCopy" Type="System.Boolean" Optional="True" Category="Deep Copy" Default="false" Description="Generate deep copy method for the collection." %>
<%@ Property Name="DeepCopyItem" Type="System.String" Optional="True" Category="Deep Copy" Default="Clone" Description="The ItemType method that creates a deep copy." %>
<%@ Property Name="KeyIndexer" Type="System.Boolean" Optional="True" Category="Key" Default="false" Description="Generate indexer for the key property." %>
<%@ Property Name="KeyType" Type="System.String" Optional="True" Category="Key" Description="The type of the key property." %>
<%@ Property Name="KeyName" Type="System.String" Optional="True" Category="Key" Description="The name of the key property." %>
<%@ Property Name="IncludeInterfaces" Type="System.Boolean" Optional="True" Category="Options" Default="true" Description="Generate required interface definitions." %>
<%@ Property Name="IncludeNamespaces" Type="System.Boolean" Optional="True" Category="Namespaces" Default="true" Description="Generate using and namespace statements." %>

<script runat="template">
<!-- #include file=CommonScript.cs -->

public override string GetFileName() {
    ValidateClassName("Collection");
    return ClassName + ".cs";
}

public bool IsKeyDefined() {
    return (KeyName != null && KeyName.Length > 0 &&
            KeyType != null && KeyType.Length > 0);
}

public void ValidateClassName(string suffix) {
    if (ClassName == null || ClassName.Length == 0)
        ClassName = ItemType + suffix;
}

public void ValidateProperties() {
    if (KeyIndexer && IsInt32(KeyType))
        throw new ApplicationException(
            "KeyIndexer cannot be True if KeyType/n" +
            "is int, Integer, Int32, or System.Int32.");

    if (KeyName == null || KeyName.Length == 0)
        KeyName = KeyType;

    ValidateClassName("Collection");
}

</script>
<% //Debugger.Break(); %>
<% ValidateProperties(); %>
<% UsingNamespace("System"); %>
<% UsingNamespace("System.Collections"); %>
<% UsingNamespace("System.ComponentModel"); %>
<% UsingNamespace(ItemNamespace); %>
<% StartNamespace(TargetNamespace); %>
    <% if (IncludeInterfaces) GenerateInterfaces("IList.cst"); %>
    #region Class <%= ClassName %>

    /// <summary>
    /// Implements a strongly typed collection of <see cref="<%= ItemType %>"/> elements.
    /// </summary>
    /// <remarks><para>
    /// <b><%= ClassName %></b> provides an <see cref="ArrayList"/>
    /// that is strongly typed for <see cref="<%= ItemType %>"/> elements.
    <% if (IsKeyDefined()) { %>
    /// </para><para>
    /// The <see cref="<%= ItemType %>.<%= KeyName %>"/> property of the
    /// <see cref="<%= ItemType %>"/> class can be used as a key
    /// to locate elements in the <b><%= ClassName %></b>.
    /// </para><para>
    /// The collection may contain multiple identical keys. All key access methods
    /// return the first occurrence of the specified key, if found. Access by key
    /// is an O(<em>N</em>) operation, where <em>N</em> is the current value of the
    /// <see cref="<%= ClassName %>.Count"/> property.
    <% } %>
    /// </para></remarks>

    [Serializable]
    <%= GetAccessModifier(Accessibility) %> class <%= ClassName %>:
        I<%= ItemType %>List, IList, ICloneable,IBindingList {
        #region Private Fields

        private const int _defaultCapacity = 16;

        private <%= ItemType %>[] _array = null;
        private int _count = 0;

        [NonSerialized]
        private int _version = 0;

        #endregion
        #region Private Constructors

        // helper type to identify private ctor
        private enum Tag { Default }

        private <%= ClassName %>(Tag tag) { }

        #endregion
        #region Public Constructors
        #region <%= ClassName %>()

        /// <overloads>
        /// Initializes a new instance of the <see cref="<%= ClassName %>"/> class.
        /// </overloads>
        /// <summary>
        /// Initializes a new instance of the <see cref="<%= ClassName %>"/> class
        /// that is empty and has the default initial capacity.
        /// </summary>
        /// <remarks>Please refer to <see cref="ArrayList()"/> for details.</remarks>

        public <%= ClassName %>() {
            this._array = new <%= ItemType %>[_defaultCapacity];
        }

        #endregion
        #region <%= ClassName %>(Int32)

        /// <summary>
        /// Initializes a new instance of the <see cref="<%= ClassName %>"/> class
        /// that is empty and has the specified initial capacity.
        /// </summary>
        /// <param name="capacity">The number of elements that the new
        /// <see cref="<%= ClassName %>"/> is initially capable of storing.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="capacity"/> is less than zero.</exception>
        /// <remarks>Please refer to <see cref="ArrayList(Int32)"/> for details.</remarks>

        public <%= ClassName %>(int capacity) {
            if (capacity < 0)
                throw new ArgumentOutOfRangeException("capacity",
                    capacity, "Argument cannot be negative.");

            this._array = new <%= ItemType %>[capacity];
        }

        #endregion
        #region <%= ClassName %>(<%= ClassName %>)

        /// <summary>
        /// Initializes a new instance of the <see cref="<%= ClassName %>"/> class
        /// that contains elements copied from the specified collection and
        /// that has the same initial capacity as the number of elements copied.
        /// </summary>
        /// <param name="collection">The <see cref="<%= ClassName %>"/>
        /// whose elements are copied to the new collection.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="collection"/> is a null reference.</exception>
        /// <remarks>Please refer to <see cref="ArrayList(ICollection)"/> for details.</remarks>

        public <%= ClassName %>(<%= ClassName %> collection) {
            if (collection == null)
                throw new ArgumentNullException("collection");

            this._array = new <%= ItemType %>[collection.Count];
            AddRange(collection);
        }

        #endregion
        #region <%= ClassName %>(<%= ItemType %>[])

        /// <summary>
        /// Initializes a new instance of the <see cref="<%= ClassName %>"/> class
        /// that contains elements copied from the specified <see cref="<%= ItemType %>"/>
        /// array and that has the same initial capacity as the number of elements copied.
        /// </summary>
        /// <param name="array">An <see cref="Array"/> of <see cref="<%= ItemType %>"/>
        /// elements that are copied to the new collection.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="array"/> is a null reference.</exception>
        /// <remarks>Please refer to <see cref="ArrayList(ICollection)"/> for details.</remarks>

        public <%= ClassName %>(<%= ItemType %>[] array) {
            if (array == null)
                throw new ArgumentNullException("array");

            this._array = new <%= ItemType %>[array.Length];
            AddRange(array);
        }

        #endregion
        #endregion
        #region Protected Properties
        #region InnerArray
       
        /// <summary>
        /// Gets the list of elements contained in the <see cref="<%= ClassName %>"/> instance.
        /// </summary>
        /// <value>
        /// A one-dimensional <see cref="Array"/> with zero-based indexing that contains all
        /// <see cref="<%= ItemType %>"/> elements in the <see cref="<%= ClassName %>"/>.
        /// </value>
        /// <remarks>
        /// Use <b>InnerArray</b> to access the element array of a <see cref="<%= ClassName %>"/>
        /// instance that might be a read-only or synchronized wrapper. This is necessary because
        /// the element array field of wrapper classes is always a null reference.
        /// </remarks>

        protected virtual <%= ItemType %>[] InnerArray {
            get { return this._array; }
        }

        #endregion
        #endregion
        #region Public Properties
        #region Capacity

        /// <summary>
        /// Gets or sets the capacity of the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <value>The number of elements that the
        /// <see cref="<%= ClassName %>"/> can contain.</value>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <b>Capacity</b> is set to a value that is less than <see cref="Count"/>.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.Capacity"/> for details.</remarks>

        public virtual int Capacity {
            get { return this._array.Length; }
            set {
                if (value == this._array.Length) return;

                if (value < this._count)
                    throw new ArgumentOutOfRangeException("Capacity",
                        value, "Value cannot be less than Count.");

                if (value == 0) {
                    this._array = new <%= ItemType %>[_defaultCapacity];
                    return;
                }

                <%= ItemType %>[] newArray = new <%= ItemType %>[value];
                Array.Copy(this._array, newArray, this._count);
                this._array = newArray;
            }
        }

        #endregion
        #region Count

        /// <summary>
        /// Gets the number of elements contained in the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <value>
        /// The number of elements contained in the <see cref="<%= ClassName %>"/>.
        /// </value>
        /// <remarks>Please refer to <see cref="ArrayList.Count"/> for details.</remarks>

        public virtual int Count {
            get { return this._count; }
        }

        #endregion
        #region IsFixedSize

        /// <summary>
        /// Gets a value indicating whether the <see cref="<%= ClassName %>"/> has a fixed size.
        /// </summary>
        /// <value><c>true</c> if the <see cref="<%= ClassName %>"/> has a fixed size;
        /// otherwise, <c>false</c>. The default is <c>false</c>.</value>
        /// <remarks>Please refer to <see cref="ArrayList.IsFixedSize"/> for details.</remarks>

        public virtual bool IsFixedSize {
            get { return false; }
        }

        #endregion
        #region IsReadOnly

        /// <summary>
        /// Gets a value indicating whether the <see cref="<%= ClassName %>"/> is read-only.
        /// </summary>
        /// <value><c>true</c> if the <see cref="<%= ClassName %>"/> is read-only;
        /// otherwise, <c>false</c>. The default is <c>false</c>.</value>
        /// <remarks>Please refer to <see cref="ArrayList.IsReadOnly"/> for details.</remarks>

        public virtual bool IsReadOnly {
            get { return false; }
        }

        #endregion
        #region IsSynchronized

        /// <summary>
        /// Gets a value indicating whether access to the <see cref="<%= ClassName %>"/>
        /// is synchronized (thread-safe).
        /// </summary>
        /// <value><c>true</c> if access to the <see cref="<%= ClassName %>"/> is
        /// synchronized (thread-safe); otherwise, <c>false</c>. The default is <c>false</c>.</value>
        /// <remarks>Please refer to <see cref="ArrayList.IsSynchronized"/> for details.</remarks>

        public virtual bool IsSynchronized {
            get { return false; }
        }

        #endregion
  #region IsUnique

  /// <summary>
  /// Gets a value indicating whether the <see cref="<%= ClassName %>"/>
  /// ensures that all elements are unique.
  /// </summary>
  /// <value>
  /// <c>true</c> if the <see cref="<%= ClassName %>"/> ensures that all
  /// elements are unique; otherwise, <c>false</c>. The default is <c>false</c>.
  /// </value>
  /// <remarks>
  /// <b>IsUnique</b> returns <c>true</c> exactly if the <see cref="<%= ClassName %>"/>
  /// is exposed through a <see cref="Unique"/> wrapper.
  /// Please refer to <see cref="Unique"/> for details.
  /// </remarks>

  public virtual bool IsUnique {
   get { return false; }
  }

  #endregion
        <% if (IsKeyDefined() && KeyIndexer) { %>
        #region Item[<%= KeyType %>]: <%= ItemType %>

        /// <overloads>
        /// Gets or sets a specific <see cref="<%= ItemType %>"/> element.
        /// </overloads>
        /// <summary>
        /// Gets the <see cref="<%= ItemType %>"/> element associated with the first
        /// occurrence of the specified <see cref="<%= ItemType %>.<%= KeyName %>"/> value.
        /// </summary>
        /// <param name="key">
        /// The <see cref="<%= ItemType %>.<%= KeyName %>"/> value whose element to get.</param>
        /// <value>The <see cref="<%= ItemType %>"/> element associated with the first
        /// occurrence of the specified <paramref name="key"/>, if found; otherwise,
        <% if (ItemValueType) { %>
        /// a default-initialized <b><%= ItemType %></b> object.
        <% } else { %>
        /// a null reference.
        <% } %>
        /// </value>
        /// <remarks>
        /// This indexer has the same effect as the <see cref="GetByKey"/> method.
        /// </remarks>

        public <%= ItemType %> this[<%= KeyType %> key] {
            get { return GetByKey(key); }
        }

        #endregion
        <% } %>
        #region Item: <%= ItemType %>

        /// <summary>
        /// Gets or sets the <see cref="<%= ItemType %>"/> element at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the
        /// <see cref="<%= ItemType %>"/> element to get or set.</param>
        /// <value>
        /// The <see cref="<%= ItemType %>"/> element at the specified <paramref name="index"/>.
        /// </value>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero.</para>
        /// <para>-or-</para>
        /// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
        /// </exception>
        /// <exception cref="NotSupportedException"><para>
        /// The property is set and the <see cref="<%= ClassName %>"/> is read-only.
        /// </para><para>-or-</para><para>
        /// The property is set, the <b><%= ClassName %></b> already contains the
        /// specified element at a different index, and the <b><%= ClassName %></b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.this"/> for details.</remarks>

        public virtual <%= ItemType %> this[int index] {
            get {
                ValidateIndex(index);
    if (index == -1 && _count > 0) index = _count-1;
                return this._array[index];
            }
            set {
                ValidateIndex(index);
                ++this._version;
                this._array[index] = value;
    OnListChanged(ListChangedType.ItemChanged,index);
            }
        }

        #endregion
        #region IList.Item: Object

        /// <summary>
        /// Gets or sets the element at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index of the element to get or set.</param>
        /// <value>
        /// The element at the specified <paramref name="index"/>. When the property
        /// is set, this value must be compatible with <see cref="<%= ItemType %>"/>.
        /// </value>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero.</para>
        /// <para>-or-</para>
        /// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
        /// </exception>
        /// <exception cref="InvalidCastException">The property is set to a value
        /// that is not compatible with <see cref="<%= ItemType %>"/>.</exception>
        /// <exception cref="NotSupportedException"><para>
        /// The property is set and the <see cref="<%= ClassName %>"/> is read-only.
        /// </para><para>-or-</para><para>
        /// The property is set, the <b><%= ClassName %></b> already contains the
        /// specified element at a different index, and the <b><%= ClassName %></b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.this"/> for details.</remarks>

        object IList.this[int index] {
            get { return this[index]; }
            set { this[index] = (<%= ItemType %>) value; OnListChanged(ListChangedType.ItemChanged,index); }
        }

        #endregion
        #region SyncRoot

        /// <summary>
        /// Gets an object that can be used to synchronize
        /// access to the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <value>An object that can be used to synchronize
        /// access to the <see cref="<%= ClassName %>"/>.
        /// </value>
        /// <remarks>Please refer to <see cref="ArrayList.SyncRoot"/> for details.</remarks>

        public virtual object SyncRoot {
            get { return this; }
        }

        #endregion
        #endregion
        #region Public Methods
        #region Add(<%= ItemType %>)

        /// <summary>
        /// Adds a <see cref="<%= ItemType %>"/> to the end of the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="value">The <see cref="<%= ItemType %>"/> object
        /// to be added to the end of the <see cref="<%= ClassName %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <returns>The <see cref="<%= ClassName %>"/> index at which the
        /// <paramref name="value"/> has been added.</returns>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> already contains the specified
        /// <paramref name="value"/>, and the <b><%= ClassName %></b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.Add"/> for details.</remarks>

        public virtual int Add(<%= ItemType %> value) {
            if (this._count == this._array.Length)
                EnsureCapacity(this._count + 1);

   ++this._version;
            this._array[this._count] = value;
   
   
   OnListChanged(ListChangedType.ItemAdded,this._count + 1);
   
            return this._count++;
        }

        #endregion
        #region IList.Add(Object)

        /// <summary>
        /// Adds an <see cref="Object"/> to the end of the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="value">
        /// The object to be added to the end of the <see cref="<%= ClassName %>"/>.
        /// This argument must be compatible with <see cref="<%= ItemType %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <returns>The <see cref="<%= ClassName %>"/> index at which the
        /// <paramref name="value"/> has been added.</returns>
        /// <exception cref="InvalidCastException"><paramref name="value"/>
        /// is not compatible with <see cref="<%= ItemType %>"/>.</exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> already contains the specified
        /// <paramref name="value"/>, and the <b><%= ClassName %></b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.Add"/> for details.</remarks>

        int IList.Add(object value) {
            return Add((<%= ItemType %>) value);
        }

        #endregion
        #region AddRange(<%= ClassName %>)

        /// <overloads>
        /// Adds a range of elements to the end of the <see cref="<%= ClassName %>"/>.
        /// </overloads>
        /// <summary>
        /// Adds the elements of another collection to the end of the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="collection">The <see cref="<%= ClassName %>"/> whose elements
        /// should be added to the end of the current collection.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="collection"/> is a null reference.</exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> already contains one or more elements
        /// in the specified <paramref name="collection"/>, and the <b><%= ClassName %></b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.AddRange"/> for details.</remarks>

        public virtual void AddRange(<%= ClassName %> collection) {
            if (collection == null)
                throw new ArgumentNullException("collection");

            if (collection.Count == 0) return;
            if (this._count + collection.Count > this._array.Length)
                EnsureCapacity(this._count + collection.Count);

            ++this._version;
            Array.Copy(collection.InnerArray, 0,
                this._array, this._count, collection.Count);
    
   OnListChanged(ListChangedType.Reset,-1);
    
            this._count += collection.Count;
        }

        #endregion
        #region AddRange(<%= ItemType %>[])

        /// <summary>
        /// Adds the elements of a <see cref="<%= ItemType %>"/> array
        /// to the end of the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="array">An <see cref="Array"/> of <see cref="<%= ItemType %>"/> elements
        /// that should be added to the end of the <see cref="<%= ClassName %>"/>.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="array"/> is a null reference.</exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> already contains one or more elements
        /// in the specified <paramref name="array"/>, and the <b><%= ClassName %></b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.AddRange"/> for details.</remarks>

        public virtual void AddRange(<%= ItemType %>[] array) {
            if (array == null)
                throw new ArgumentNullException("array");

            if (array.Length == 0) return;
            if (this._count + array.Length > this._array.Length)
                EnsureCapacity(this._count + array.Length);

            ++this._version;
            Array.Copy(array, 0, this._array, this._count, array.Length);
   OnListChanged(ListChangedType.Reset,-1);
            this._count += array.Length;
        }

        #endregion
        #region BinarySearch

        /// <summary>
        /// Searches the entire sorted <see cref="<%= ClassName %>"/> for an
        /// <see cref="<%= ItemType %>"/> element using the default comparer
        /// and returns the zero-based index of the element.
        /// </summary>
        /// <param name="value">The <see cref="<%= ItemType %>"/> object
        /// to locate in the <see cref="<%= ClassName %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <returns>The zero-based index of <paramref name="value"/> in the sorted
        /// <see cref="<%= ClassName %>"/>, if <paramref name="value"/> is found;
        /// otherwise, a negative number, which is the bitwise complement of the index
        /// of the next element that is larger than <paramref name="value"/> or, if there
        /// is no larger element, the bitwise complement of <see cref="Count"/>.</returns>
        /// <exception cref="InvalidOperationException">
        /// Neither <paramref name="value"/> nor the elements of the <see cref="<%= ClassName %>"/>
        /// implement the <see cref="IComparable"/> interface.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.BinarySearch"/> for details.</remarks>

        public virtual int BinarySearch(<%= ItemType %> value) {
        <% if (ItemCustomSearch) { %>
            if (this._count == 0) return ~0;
            int index, left = 0, right = this._count - 1;

        <% if (!ItemValueType) { %>
            if ((object) value == null) {
                do {
                    index = (left + right) / 2;
                    if ((object) this._array[index] == null)
                        return index;
                    right = index - 1;
                } while (left <= right);

                return ~left;
            }

        <% } %>
            do {
                index = (left + right) / 2;
                int result = value.CompareTo(this._array[index]);

                if (result == 0)
                    return index;
                else if (result < 0)
                    right = index - 1;
                else
                    left = index + 1;
            } while (left <= right);

            return ~left;
        <% } else { %>
            return Array.BinarySearch(this._array, 0, this._count, value);
        <% } %>
        }

        #endregion
        #region Clear

        /// <summary>
        /// Removes all elements from the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.Clear"/> for details.</remarks>

        public virtual void Clear() {
            if (this._count == 0) return;

            ++this._version;
            Array.Clear(this._array, 0, this._count);
   OnListChanged(ListChangedType.Reset,-1);
            this._count = 0;
        }

        #endregion
        #region Clone

        /// <summary>
        /// Creates a shallow copy of the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <returns>A shallow copy of the <see cref="<%= ClassName %>"/>.</returns>
        /// <remarks>Please refer to <see cref="ArrayList.Clone"/> for details.</remarks>

        public virtual object Clone() {
            <%= ClassName %> collection = new <%= ClassName %>(this._count);

            Array.Copy(this._array, 0, collection._array, 0, this._count);
            collection._count = this._count;
            collection._version = this._version;

            return collection;
        }

        #endregion
        #region Contains(<%= ItemType %>)

        /// <summary>
        /// Determines whether the <see cref="<%= ClassName %>"/>
        /// contains the specified <see cref="<%= ItemType %>"/> element.
        /// </summary>
        /// <param name="value">The <see cref="<%= ItemType %>"/> object
        /// to locate in the <see cref="<%= ClassName %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <returns><c>true</c> if <paramref name="value"/> is found in the
        /// <see cref="<%= ClassName %>"/>; otherwise, <c>false</c>.</returns>
        /// <remarks>Please refer to <see cref="ArrayList.Contains"/> for details.</remarks>

        public bool Contains(<%= ItemType %> value) {
            return (IndexOf(value) >= 0);
        }

        #endregion
        #region IList.Contains(Object)

        /// <summary>
        /// Determines whether the <see cref="<%= ClassName %>"/> contains the specified element.
        /// </summary>
        /// <param name="value">The object to locate in the <see cref="<%= ClassName %>"/>.
        /// This argument must be compatible with <see cref="<%= ItemType %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <returns><c>true</c> if <paramref name="value"/> is found in the
        /// <see cref="<%= ClassName %>"/>; otherwise, <c>false</c>.</returns>
        /// <exception cref="InvalidCastException"><paramref name="value"/>
        /// is not compatible with <see cref="<%= ItemType %>"/>.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.Contains"/> for details.</remarks>

        bool IList.Contains(object value) {
            return Contains((<%= ItemType %>) value);
        }

        #endregion
        <% if (IsKeyDefined()) { %>
        #region ContainsKey

        /// <summary>
        /// Determines whether the <see cref="<%= ClassName %>"/> contains
        /// the specified <see cref="<%= ItemType %>.<%= KeyName %>"/> value.
        /// </summary>
        /// <param name="key">The <see cref="<%= ItemType %>.<%= KeyName %>"/>
        /// value to locate in the <see cref="<%= ClassName %>"/>.</param>
        /// <returns><c>true</c> if <paramref name="key"/> is found in the
        /// <see cref="<%= ClassName %>"/>; otherwise, <c>false</c>.</returns>
        /// <remarks>
        /// <b>ContainsKey</b> is similar to <see cref="Contains"/> but compares the specified
        /// <paramref name="key"/> to the value of the <see cref="<%= ItemType %>.<%= KeyName %>"/>
        /// property of each <see cref="<%= ItemType %>"/> element, rather than to the element itself.
        /// </remarks>

        public bool ContainsKey(<%= KeyType %> key) {
            return (IndexOfKey(key) >= 0);
        }

        #endregion
        <% } %>
        <% if (DeepCopy) { %>
        #region Copy
       
        /// <summary>
        /// Creates a deep copy of the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <returns>A deep copy of the <see cref="<%= ClassName %>"/>.</returns>
        /// <remarks><para>
        <% if (ItemValueType) { %>
        /// <b>Copy</b> has the same effect as <see cref="Clone"/>
        /// because <see cref="<%= ItemType %>"/> is a value type.
        <% } else if (IsString(ItemType)) { %>
        /// <b>Copy</b> has the same effect as <see cref="Clone"/>
        /// because strings are immutable in the .NET Framework.
        <% } else { %>
        /// <b>Copy</b> is similar to <see cref="Clone"/> but creates a deep copy of
        /// every <see cref="<%= ItemType %>"/> element in the <see cref="<%= ClassName %>"/>
        /// by invoking its <see cref="<%= ItemType %>.<%= DeepCopyItem %>"/> method.
        <% } %>
        /// </para><para>
        /// <b>Copy</b> never returns a <b><%= ClassName %></b> with a read-only,
        /// synchronized, or unique wrapper, whereas <b>Clone</b> preserves any
        /// wrappers around this <b><%= ClassName %></b>.
        /// </para></remarks>

        public virtual <%= ClassName %> Copy() {
            <%= ClassName %> collection = new <%= ClassName %>(this._count);

        <% if (ItemValueType || IsString(ItemType)) { %>
            Array.Copy(this._array, 0, collection._array, 0, this._count);
        <% } else { %>
            for (int i = 0; i < this._count; i++)
                if ((object) this._array[i] != null)
                    collection._array[i] = (<%= ItemType %>) this._array[i].<%= DeepCopyItem %>();

        <% } %>
            collection._count = this._count;
            collection._version = this._version;

            return collection;
        }
       
        #endregion
        <% } %>
        #region CopyTo(<%= ItemType %>[])

        /// <overloads>
        /// Copies the <see cref="<%= ClassName %>"/> or a portion of it to a one-dimensional array.
        /// </overloads>
        /// <summary>
        /// Copies the entire <see cref="<%= ClassName %>"/> to a one-dimensional <see cref="Array"/>
        /// of <see cref="<%= ItemType %>"/> elements, starting at the beginning of the target array.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the
        /// <see cref="<%= ItemType %>"/> elements copied from the <see cref="<%= ClassName %>"/>.
        /// The <b>Array</b> must have zero-based indexing.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="array"/> is a null reference.</exception>
        /// <exception cref="ArgumentException">
        /// The number of elements in the source <see cref="<%= ClassName %>"/> is greater
        /// than the available space in the destination <paramref name="array"/>.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.CopyTo"/> for details.</remarks>

        public virtual void CopyTo(<%= ItemType %>[] array) {
            CheckTargetArray(array, 0);
            Array.Copy(this._array, array, this._count);
        }

        #endregion
        #region CopyTo(<%= ItemType %>[], Int32)

        /// <summary>
        /// Copies the entire <see cref="<%= ClassName %>"/> to a one-dimensional <see cref="Array"/>
        /// of <see cref="<%= ItemType %>"/> elements, starting at the specified index of the target array.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the
        /// <see cref="<%= ItemType %>"/> elements copied from the <see cref="<%= ClassName %>"/>.
        /// The <b>Array</b> must have zero-based indexing.</param>
        /// <param name="arrayIndex">The zero-based index in <paramref name="array"/>
        /// at which copying begins.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="array"/> is a null reference.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="arrayIndex"/> is less than zero.</exception>
        /// <exception cref="ArgumentException"><para>
        /// <paramref name="arrayIndex"/> is equal to or greater than the length of <paramref name="array"/>.
        /// </para><para>-or-</para><para>
        /// The number of elements in the source <see cref="<%= ClassName %>"/> is greater than the
        /// available space from <paramref name="arrayIndex"/> to the end of the destination
        /// <paramref name="array"/>.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.CopyTo"/> for details.</remarks>

        public virtual void CopyTo(<%= ItemType %>[] array, int arrayIndex) {
            CheckTargetArray(array, arrayIndex);
            Array.Copy(this._array, 0, array, arrayIndex, this._count);
        }

        #endregion
        #region ICollection.CopyTo(Array, Int32)

        /// <summary>
        /// Copies the entire <see cref="<%= ClassName %>"/> to a one-dimensional <see cref="Array"/>,
        /// starting at the specified index of the target array.
        /// </summary>
        /// <param name="array">The one-dimensional <see cref="Array"/> that is the destination of the
        /// <see cref="<%= ItemType %>"/> elements copied from the <see cref="<%= ClassName %>"/>.
        /// The <b>Array</b> must have zero-based indexing.</param>
        /// <param name="arrayIndex">The zero-based index in <paramref name="array"/>
        /// at which copying begins.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="array"/> is a null reference.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="arrayIndex"/> is less than zero.</exception>
        /// <exception cref="ArgumentException"><para>
        /// <paramref name="array"/> is multidimensional.
        /// </para><para>-or-</para><para>
        /// <paramref name="arrayIndex"/> is equal to or greater than the length of <paramref name="array"/>.
        /// </para><para>-or-</para><para>
        /// The number of elements in the source <see cref="<%= ClassName %>"/> is greater than the
        /// available space from <paramref name="arrayIndex"/> to the end of the destination
        /// <paramref name="array"/>.</para></exception>
        /// <exception cref="InvalidCastException">
        /// The <see cref="<%= ItemType %>"/> type cannot be cast automatically
        /// to the type of the destination <paramref name="array"/>.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.CopyTo"/> for details.</remarks>

        void ICollection.CopyTo(Array array, int arrayIndex) {
            CheckTargetArray(array, arrayIndex);
            CopyTo((<%= ItemType %>[]) array, arrayIndex);
        }

        #endregion
        <% if (IsKeyDefined()) { %>
        #region GetByKey

        /// <summary>
        /// Gets the <see cref="<%= ItemType %>"/> element associated with the first
        /// occurrence of the specified <see cref="<%= ItemType %>.<%= KeyName %>"/> value.
        /// </summary>
        /// <param name="key">
        /// The <see cref="<%= ItemType %>.<%= KeyName %>"/> value whose element to get.</param>
        /// <returns>The <see cref="<%= ItemType %>"/> element associated with the first
        /// occurrence of the specified <paramref name="key"/>, if found; otherwise,
        <% if (ItemValueType) { %>
        /// a default-initialized <b><%= ItemType %></b> object.
        <% } else { %>
        /// a null reference.
        <% } %>
        /// </returns>
        /// <remarks>
        /// <b>GetByKey</b> compares the specified <paramref name="key"/> to the value
        /// of the <see cref="<%= ItemType %>.<%= KeyName %>"/> property of each
        /// <see cref="<%= ItemType %>"/> element, and returns the first matching element.
        /// </remarks>

        public virtual <%= ItemType %> GetByKey(<%= KeyType %> key) {
            int index = IndexOfKey(key);
            if (index >= 0) return this._array[index];
        <% if (ItemValueType) { %>
            return new <%= ItemType %>();
        <% } else { %>
            return null;
        <% } %>
        }

        #endregion
        <% } %>
        #region GetEnumerator: I<%= ItemType %>Enumerator

        /// <summary>
        /// Returns an <see cref="I<%= ItemType %>Enumerator"/> that can
        /// iterate through the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <returns>An <see cref="I<%= ItemType %>Enumerator"/>
        /// for the entire <see cref="<%= ClassName %>"/>.</returns>
        /// <remarks>Please refer to <see cref="ArrayList.GetEnumerator"/> for details.</remarks>

        public virtual I<%= ItemType %>Enumerator GetEnumerator() {
            return new Enumerator(this);
        }

        #endregion
        #region IEnumerable.GetEnumerator: IEnumerator

        /// <summary>
        /// Returns an <see cref="IEnumerator"/> that can
        /// iterate through the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <returns>An <see cref="IEnumerator"/>
        /// for the entire <see cref="<%= ClassName %>"/>.</returns>
        /// <remarks>Please refer to <see cref="ArrayList.GetEnumerator"/> for details.</remarks>

        IEnumerator IEnumerable.GetEnumerator() {
            return (IEnumerator) GetEnumerator();
        }

        #endregion
        #region IndexOf(<%= ItemType %>)

        /// <summary>
        /// Returns the zero-based index of the first occurrence of the specified
        /// <see cref="<%= ItemType %>"/> in the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="value">The <see cref="<%= ItemType %>"/> object
        /// to locate in the <see cref="<%= ClassName %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <returns>
        /// The zero-based index of the first occurrence of <paramref name="value"/>
        /// in the <see cref="<%= ClassName %>"/>, if found; otherwise, -1.
        /// </returns>
        /// <remarks>Please refer to <see cref="ArrayList.IndexOf"/> for details.</remarks>

        public virtual int IndexOf(<%= ItemType %> value) {
        <% if (ItemCustomSearch) { %>

        <% if (!ItemValueType) { %>
            if ((object) value == null) {
                for (int i = 0; i < this._count; i++)
                    if ((object) this._array[i] == null)
                        return i;

                return -1;
            }
        <% } %>

            for (int i = 0; i < this._count; i++)
                if (value.Equals(this._array[i]))
                    return i;

            return -1;
        <% } else { %>
            return Array.IndexOf(this._array, value, 0, this._count);
        <% } %>
        }

        #endregion
        #region IList.IndexOf(Object)

        /// <summary>
        /// Returns the zero-based index of the first occurrence of the specified
        /// <see cref="Object"/> in the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="value">The object to locate in the <see cref="<%= ClassName %>"/>.
        /// This argument must be compatible with <see cref="<%= ItemType %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <returns>
        /// The zero-based index of the first occurrence of <paramref name="value"/>
        /// in the <see cref="<%= ClassName %>"/>, if found; otherwise, -1.
        /// </returns>
        /// <exception cref="InvalidCastException"><paramref name="value"/>
        /// is not compatible with <see cref="<%= ItemType %>"/>.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.IndexOf"/> for details.</remarks>

        int IList.IndexOf(object value) {
            return IndexOf((<%= ItemType %>) value);
        }

        #endregion
        <% if (IsKeyDefined()) { %>
        #region IndexOfKey

        /// <summary>
        /// Returns the zero-based index of the first occurrence of the specified
        /// <see cref="<%= ItemType %>.<%= KeyName %>"/> value in the
        /// <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="key">The <see cref="<%= ItemType %>.<%= KeyName %>"/>
        /// value to locate in the <see cref="<%= ClassName %>"/>.</param>
        /// <returns>
        /// The zero-based index of the first occurrence of <paramref name="key"/>
        /// in the <see cref="<%= ClassName %>"/>, if found; otherwise, -1.
        /// </returns>
        /// <remarks>
        /// <b>IndexOfKey</b> is similar to <see cref="IndexOf"/> but compares the specified
        /// <paramref name="key"/> to the value of the <see cref="<%= ItemType %>.<%= KeyName %>"/>
        /// property of each <see cref="<%= ItemType %>"/> element, rather than to the element itself.
        /// </remarks>

        public virtual int IndexOfKey(<%= KeyType %> key) {

            for (int i = 0; i < this._count; i++) {
        <% if (!ItemValueType) { %>
                if ((object) this._array[i] == null) continue;
        <% } %>
                if (this._array[i].<%= KeyName %> == key)
                    return i;
            }

            return -1;
        }

        #endregion
        <% } %>
        #region Insert(Int32, <%= ItemType %>)

        /// <summary>
        /// Inserts a <see cref="<%= ItemType %>"/> element into the
        /// <see cref="<%= ClassName %>"/> at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which <paramref name="value"/>
        /// should be inserted.</param>
        /// <param name="value">The <see cref="<%= ItemType %>"/> object
        /// to insert into the <see cref="<%= ClassName %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero.</para>
        /// <para>-or-</para>
        /// <para><paramref name="index"/> is greater than <see cref="Count"/>.</para>
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> already contains the specified
        /// <paramref name="value"/>, and the <b><%= ClassName %></b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.Insert"/> for details.</remarks>

        public virtual void Insert(int index, <%= ItemType %> value) {
            if (index < 0)
                throw new ArgumentOutOfRangeException("index",
                    index, "Argument cannot be negative.");

            if (index > this._count)
                throw new ArgumentOutOfRangeException("index",
                    index, "Argument cannot exceed Count.");

            if (this._count == this._array.Length)
                EnsureCapacity(this._count + 1);

            ++this._version;
            if (index < this._count)
                Array.Copy(this._array, index,
                    this._array, index + 1, this._count - index);

            this._array[index] = value;
            ++this._count;
      OnListChanged(ListChangedType.Reset,-1);
        }

        #endregion
        #region IList.Insert(Int32, Object)

        /// <summary>
        /// Inserts an element into the <see cref="<%= ClassName %>"/> at the specified index.
        /// </summary>
        /// <param name="index">The zero-based index at which <paramref name="value"/>
        /// should be inserted.</param>
        /// <param name="value">The object to insert into the <see cref="<%= ClassName %>"/>.
        /// This argument must be compatible with <see cref="<%= ItemType %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero.</para>
        /// <para>-or-</para>
        /// <para><paramref name="index"/> is greater than <see cref="Count"/>.</para>
        /// </exception>
        /// <exception cref="InvalidCastException"><paramref name="value"/>
        /// is not compatible with <see cref="<%= ItemType %>"/>.</exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> already contains the specified
        /// <paramref name="value"/>, and the <b><%= ClassName %></b>
        /// ensures that all elements are unique.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.Insert"/> for details.</remarks>

        void IList.Insert(int index, object value) {
            Insert(index, (<%= ItemType %>) value);
        }

        #endregion
        #region ReadOnly

        /// <summary>
        /// Returns a read-only wrapper for the specified <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="collection">The <see cref="<%= ClassName %>"/> to wrap.</param>
        /// <returns>A read-only wrapper around <paramref name="collection"/>.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="collection"/> is a null reference.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.ReadOnly"/> for details.</remarks>

        public static <%= ClassName %> ReadOnly(<%= ClassName %> collection) {
            if (collection == null)
                throw new ArgumentNullException("collection");

            return new ReadOnlyList(collection);
        }

        #endregion
        #region Remove(<%= ItemType %>)

        /// <summary>
        /// Removes the first occurrence of the specified <see cref="<%= ItemType %>"/>
        /// from the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="value">The <see cref="<%= ItemType %>"/> object
        /// to remove from the <see cref="<%= ClassName %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.Remove"/> for details.</remarks>

        public virtual void Remove(<%= ItemType %> value) {
            int index = IndexOf(value);
            if (index >= 0){
   RemoveAt(index);
   OnListChanged(ListChangedType.ItemDeleted,index);
   }
        }

        #endregion
        #region IList.Remove(Object)

        /// <summary>
        /// Removes the first occurrence of the specified <see cref="Object"/>
        /// from the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="value">The object to remove from the <see cref="<%= ClassName %>"/>.
        /// This argument must be compatible with <see cref="<%= ItemType %>"/>.
        <% if (!ItemValueType) { %>
        /// This argument can be a null reference.
        <% } %>
        /// </param>
        /// <exception cref="InvalidCastException"><paramref name="value"/>
        /// is not compatible with <see cref="<%= ItemType %>"/>.</exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.Remove"/> for details.</remarks>

        void IList.Remove(object value) {
            Remove((<%= ItemType %>) value);
        }

        #endregion
        #region RemoveAt

        /// <summary>
        /// Removes the element at the specified index of the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="index">The zero-based index of the element to remove.</param>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero.</para>
        /// <para>-or-</para>
        /// <para><paramref name="index"/> is equal to or greater than <see cref="Count"/>.</para>
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.RemoveAt"/> for details.</remarks>

        public virtual void RemoveAt(int index) {
            ValidateIndex(index);

            ++this._version;
            if (index < --this._count)
                Array.Copy(this._array, index + 1,
                    this._array, index, this._count - index);

        <% if (ItemValueType) { %>
            this._array[this._count] = new <%= ItemType %>();
        <% } else { %>
            this._array[this._count] = null;
        <% } %>
  
  OnListChanged(ListChangedType.ItemDeleted,index);
  
        }

        #endregion
        #region RemoveRange

        /// <summary>
        /// Removes the specified range of elements from the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="index">The zero-based starting index of the range
        /// of elements to remove.</param>
        /// <param name="count">The number of elements to remove.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="index"/> and <paramref name="count"/> do not denote a
        /// valid range of elements in the <see cref="<%= ClassName %>"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero.</para>
        /// <para>-or-</para>
        /// <para><paramref name="count"/> is less than zero.</para>
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.RemoveRange"/> for details.</remarks>

        public virtual void RemoveRange(int index, int count) {
            if (index < 0)
                throw new ArgumentOutOfRangeException("index",
                    index, "Argument cannot be negative.");

            if (count < 0)
                throw new ArgumentOutOfRangeException("count",
                    count, "Argument cannot be negative.");

            if (index + count > this._count)
                throw new ArgumentException(
                    "Arguments denote invalid range of elements.");

            if (count == 0) return;

            ++this._version;
            this._count -= count;

            if (index < this._count)
                Array.Copy(this._array, index + count,
                    this._array, index, this._count - index);

            Array.Clear(this._array, this._count, count);
   
   OnListChanged(ListChangedType.Reset,-1);
   
        }

        #endregion
        #region Reverse()

        /// <overloads>
        /// Reverses the order of the elements in the
        /// <see cref="<%= ClassName %>"/> or a portion of it.
        /// </overloads>
        /// <summary>
        /// Reverses the order of the elements in the entire <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <exception cref="NotSupportedException">
        /// The <see cref="<%= ClassName %>"/> is read-only.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.Reverse"/> for details.</remarks>

        public virtual void Reverse() {
           if (this._count <= 1) return;
           ++this._version;
           Array.Reverse(this._array, 0, this._count);
   OnListChanged(ListChangedType.Reset,-1);
        }

        #endregion
        #region Reverse(Int32, Int32)

        /// <summary>
        /// Reverses the order of the elements in the specified range.
        /// </summary>
        /// <param name="index">The zero-based starting index of the range
        /// of elements to reverse.</param>
        /// <param name="count">The number of elements to reverse.</param>
        /// <exception cref="ArgumentException">
        /// <paramref name="index"/> and <paramref name="count"/> do not denote a
        /// valid range of elements in the <see cref="<%= ClassName %>"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero.</para>
        /// <para>-or-</para>
        /// <para><paramref name="count"/> is less than zero.</para>
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// The <see cref="<%= ClassName %>"/> is read-only.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.Reverse"/> for details.</remarks>

        public virtual void Reverse(int index, int count) {
            if (index < 0)
                throw new ArgumentOutOfRangeException("index",
                    index, "Argument cannot be negative.");

            if (count < 0)
                throw new ArgumentOutOfRangeException("count",
                    count, "Argument cannot be negative.");

            if (index + count > this._count)
                throw new ArgumentException(
                    "Arguments denote invalid range of elements.");

           if (count <= 1 || this._count <= 1) return;
           ++this._version;
           Array.Reverse(this._array, index, count);
  OnListChanged(ListChangedType.Reset,-1);
        }

        #endregion
        #region Sort()

        /// <overloads>
        /// Sorts the elements in the <see cref="<%= ClassName %>"/> or a portion of it.
        /// </overloads>
        /// <summary>
        /// Sorts the elements in the entire <see cref="<%= ClassName %>"/>
        /// using the <see cref="IComparable"/> implementation of each element.
        /// </summary>
        /// <exception cref="NotSupportedException">
        /// The <see cref="<%= ClassName %>"/> is read-only.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.Sort"/> for details.</remarks>

        public virtual void Sort() {
            if (this._count <= 1) return;
            ++this._version;
            Array.Sort(this._array, 0, this._count);
   OnListChanged(ListChangedType.Reset,-1);
        }

        #endregion
        #region Sort(IComparer)

        /// <summary>
        /// Sorts the elements in the entire <see cref="<%= ClassName %>"/>
        /// using the specified <see cref="IComparer"/> interface.
        /// </summary>
        /// <param name="comparer">
        /// <para>The <see cref="IComparer"/> implementation to use when comparing elements.</para>
        /// <para>-or-</para>
        /// <para>A null reference to use the <see cref="IComparable"/> implementation
        /// of each element.</para></param>
        /// <exception cref="NotSupportedException">
        /// The <see cref="<%= ClassName %>"/> is read-only.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.Sort"/> for details.</remarks>

        public virtual void Sort(IComparer comparer) {
            if (this._count <= 1) return;
            ++this._version;
            Array.Sort(this._array, 0, this._count, comparer);
   OnListChanged(ListChangedType.Reset,-1);
        }

        #endregion
        #region Sort(Int32, Int32, IComparer)

        /// <summary>
        /// Sorts the elements in the specified range
        /// using the specified <see cref="IComparer"/> interface.
        /// </summary>
        /// <param name="index">The zero-based starting index of the range
        /// of elements to sort.</param>
        /// <param name="count">The number of elements to sort.</param>
        /// <param name="comparer">
        /// <para>The <see cref="IComparer"/> implementation to use when comparing elements.</para>
        /// <para>-or-</para>
        /// <para>A null reference to use the <see cref="IComparable"/> implementation
        /// of each element.</para></param>
        /// <exception cref="ArgumentException">
        /// <paramref name="index"/> and <paramref name="count"/> do not denote a
        /// valid range of elements in the <see cref="<%= ClassName %>"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <para><paramref name="index"/> is less than zero.</para>
        /// <para>-or-</para>
        /// <para><paramref name="count"/> is less than zero.</para>
        /// </exception>
        /// <exception cref="NotSupportedException">
        /// The <see cref="<%= ClassName %>"/> is read-only.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.Sort"/> for details.</remarks>

        public virtual void Sort(int index, int count, IComparer comparer) {
            if (index < 0)
                throw new ArgumentOutOfRangeException("index",
                    index, "Argument cannot be negative.");

            if (count < 0)
                throw new ArgumentOutOfRangeException("count",
                    count, "Argument cannot be negative.");

            if (index + count > this._count)
                throw new ArgumentException(
                    "Arguments denote invalid range of elements.");

           if (count <= 1 || this._count <= 1) return;
            ++this._version;
            Array.Sort(this._array, index, count, comparer);
   OnListChanged(ListChangedType.Reset,-1);
        }

        #endregion
        #region Synchronized

        /// <summary>
        /// Returns a synchronized (thread-safe) wrapper
        /// for the specified <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <param name="collection">The <see cref="<%= ClassName %>"/> to synchronize.</param>
        /// <returns>
        /// A synchronized (thread-safe) wrapper around <paramref name="collection"/>.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="collection"/> is a null reference.</exception>
        /// <remarks>Please refer to <see cref="ArrayList.Synchronized"/> for details.</remarks>

        public static <%= ClassName %> Synchronized(<%= ClassName %> collection) {
            if (collection == null)
                throw new ArgumentNullException("collection");

            return new SyncList(collection);
        }

        #endregion
        #region ToArray

        /// <summary>
        /// Copies the elements of the <see cref="<%= ClassName %>"/> to a new
        /// <see cref="Array"/> of <see cref="<%= ItemType %>"/> elements.
        /// </summary>
        /// <returns>A one-dimensional <see cref="Array"/> of <see cref="<%= ItemType %>"/>
        /// elements containing copies of the elements of the <see cref="<%= ClassName %>"/>.</returns>
        /// <remarks>Please refer to <see cref="ArrayList.ToArray"/> for details.</remarks>

        public virtual <%= ItemType %>[] ToArray() {
            <%= ItemType %>[] array = new <%= ItemType %>[this._count];
            Array.Copy(this._array, array, this._count);
            return array;
        }

        #endregion
        #region TrimToSize

        /// <summary>
        /// Sets the capacity to the actual number of elements in the <see cref="<%= ClassName %>"/>.
        /// </summary>
        /// <exception cref="NotSupportedException">
        /// <para>The <see cref="<%= ClassName %>"/> is read-only.</para>
        /// <para>-or-</para>
        /// <para>The <b><%= ClassName %></b> has a fixed size.</para></exception>
        /// <remarks>Please refer to <see cref="ArrayList.TrimToSize"/> for details.</remarks>

        public virtual void TrimToSize() {
            Capacity = this._count;
        }

        #endregion
        #region Unique

        /// <summary>
        /// Returns a wrapper for the specified <see cref="<%= ClassName %>"/>
        /// ensuring that all elements are unique.
        /// </summary>
        /// <param name="collection">The <see cref="<%= ClassName %>"/> to wrap.</param>   
        /// <returns>
        /// A wrapper around <paramref name="collection"/> ensuring that all elements are unique.
        /// </returns>
        /// <exception cref="ArgumentException">
        /// <paramref name="collection"/> contains duplicate elements.</exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="collection"/> is a null reference.</exception>
        /// <remarks><para>
        /// The <b>Unique</b> wrapper provides a set-like collection by ensuring
        /// that all elements in the <see cref="<%= ClassName %>"/> are unique.
        /// </para><para>
        /// <b>Unique</b> raises an <see cref="ArgumentException"/> if the specified
        /// <paramref name="collection"/> contains any duplicate elements. The returned
        /// wrapper raises a <see cref="NotSupportedException"/> whenever the user attempts
        /// to add an element that is already contained in the <b><%= ClassName %></b>.
        /// </para><para>
        /// <strong>Note:</strong> The <b>Unique</b> wrapper reflects any changes made
        /// to the underlying <paramref name="collection"/>, including the possible
        /// creation of duplicate elements. The uniqueness of all elements is therefore
        /// no longer assured if the underlying collection is manipulated directly.
        /// </para></remarks>

        public static <%= ClassName %> Unique(<%= ClassName %> collection) {
            if (collection == null)
                throw new ArgumentNullException("collection");

            for (int i = collection.Count - 1; i > 0; i--)
                if (collection.IndexOf(collection[i]) < i)
                    throw new ArgumentException("Argument cannot contain duplicate elements.","collection");

            return new UniqueList(collection);
        }

        #endregion
        #endregion
        #region Private Methods
        #region CheckEnumIndex

        private void CheckEnumIndex(int index) {
            if (index < 0 || index >= this._count)
                throw new InvalidOperationException(
                    "Enumerator is not on a collection element.");
        }

        #endregion
        #region CheckEnumVersion

        private void CheckEnumVersion(int version) {
            if (version != this._version)
                throw new InvalidOperationException(
                    "Enumerator invalidated by modification to collection.");
        }

        #endregion
        #region CheckTargetArray

        private void CheckTargetArray(Array array, int arrayIndex) {
            if (array == null)
                throw new ArgumentNullException("array");
            if (array.Rank > 1)
                throw new ArgumentException(
                    "Argument cannot be multidimensional.", "array");

            if (arrayIndex < 0)
                throw new ArgumentOutOfRangeException("arrayIndex",
                    arrayIndex, "Argument cannot be negative.");
            if (arrayIndex >= array.Length)
                throw new ArgumentException(
                    "Argument must be less than array length.", "arrayIndex");

            if (this._count > array.Length - arrayIndex)
                throw new ArgumentException(
                    "Argument section must be large enough for collection.", "array");
        }

        #endregion
        #region EnsureCapacity

        private void EnsureCapacity(int minimum) {
            int newCapacity = (this._array.Length == 0 ?
                _defaultCapacity : this._array.Length * 2);

            if (newCapacity < minimum) newCapacity = minimum;
            Capacity = newCapacity;
        }

        #endregion
        #region ValidateIndex

        private void ValidateIndex(int index) {
  
   if (index == -1 && _count > 0)
   {
    return;
   }
            if (index < 0)
                throw new ArgumentOutOfRangeException("index",
                    index, "Argument cannot be negative.");

            if (index >= this._count)
                throw new ArgumentOutOfRangeException("index",
                    index, "Argument must be less than Count.");
        }

        #endregion
        #endregion
        #region Class Enumerator

        [Serializable]
        private sealed class Enumerator:
            I<%= ItemType %>Enumerator, IEnumerator {
            #region Private Fields

            private readonly <%= ClassName %> _collection;
            private readonly int _version;
            private int _index;

            #endregion
            #region Internal Constructors

            internal Enumerator(<%= ClassName %> collection) {
                this._collection = collection;
                this._version = collection._version;
                this._index = -1;
            }

            #endregion
            #region Public Properties

            public <%= ItemType %> Current {
                get {
                    this._collection.CheckEnumIndex(this._index);
                    this._collection.CheckEnumVersion(this._version);
                    return this._collection[this._index];
                }
            }

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

            #endregion
            #region Public Methods

            public bool MoveNext() {
                this._collection.CheckEnumVersion(this._version);
                return (++this._index < this._collection.Count);
            }

            public void Reset() {
                this._collection.CheckEnumVersion(this._version);
                this._index = -1;
            }

            #endregion
        }

        #endregion
        #region Class ReadOnlyList

        [Serializable]
        private sealed class ReadOnlyList: <%= ClassName %> {
            #region Private Fields

            private <%= ClassName %> _collection;

            #endregion
            #region Internal Constructors

            internal ReadOnlyList(<%= ClassName %> collection):
                base(Tag.Default) {
                this._collection = collection;
            }

            #endregion
            #region Protected Properties

            protected override <%= ItemType %>[] InnerArray {
                get { return this._collection.InnerArray; }
            }

            #endregion
            #region Public Properties

            public override int Capacity {
                get { return this._collection.Capacity; }
                set { throw new NotSupportedException(
                        "Read-only collections cannot be modified."); }
            }

            public override int Count {
                get { return this._collection.Count; }
            }

            public override bool IsFixedSize {
                get { return true; }
            }

            public override bool IsReadOnly {
                get { return true; }
            }

            public override bool IsSynchronized {
                get { return this._collection.IsSynchronized; }
            }

            public override bool IsUnique {
                get { return this._collection.IsUnique; }
            }

            public override <%= ItemType %> this[int index] {
                get { return this._collection[index]; }
                set { throw new NotSupportedException(
                        "Read-only collections cannot be modified."); }
            }

            public override object SyncRoot {
                get { return this._collection.SyncRoot; }
            }

            #endregion
            #region Public Methods

            public override int Add(<%= ItemType %> value) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void AddRange(<%= ClassName %> collection) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void AddRange(<%= ItemType %>[] array) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override int BinarySearch(<%= ItemType %> value) {
                return this._collection.BinarySearch(value);
            }

            public override void Clear() {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override object Clone() {
                return new ReadOnlyList((<%= ClassName %>) this._collection.Clone());
            }
            <% if (DeepCopy) { %>

            public override <%= ClassName %> Copy() {
                return this._collection.Copy();
            }
            <% } %>

            public override void CopyTo(<%= ItemType %>[] array) {
                this._collection.CopyTo(array);
            }

            public override void CopyTo(<%= ItemType %>[] array, int arrayIndex) {
                this._collection.CopyTo(array, arrayIndex);
            }
            <% if (IsKeyDefined()) { %>

            public override <%= ItemType %> GetByKey(<%= KeyType %> key) {
                return this._collection.GetByKey(key);
            }
            <% } %>

            public override I<%= ItemType %>Enumerator GetEnumerator() {
                return this._collection.GetEnumerator();
            }

            public override int IndexOf(<%= ItemType %> value) {
                return this._collection.IndexOf(value);
            }
            <% if (IsKeyDefined()) { %>

            public override int IndexOfKey(<%= KeyType %> key) {
                return this._collection.IndexOfKey(key);
            }
            <% } %>

            public override void Insert(int index, <%= ItemType %> value) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void Remove(<%= ItemType %> value) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void RemoveAt(int index) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void RemoveRange(int index, int count) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void Reverse() {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void Reverse(int index, int count) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void Sort() {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void Sort(IComparer comparer) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override void Sort(int index, int count, IComparer comparer) {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            public override <%= ItemType %>[] ToArray() {
                return this._collection.ToArray();
            }

            public override void TrimToSize() {
                throw new NotSupportedException(
                    "Read-only collections cannot be modified.");
            }

            #endregion
        }

        #endregion
        #region Class SyncList

        [Serializable]
        private sealed class SyncList: <%= ClassName %> {
            #region Private Fields

            private <%= ClassName %> _collection;
            private object _root;

            #endregion
            #region Internal Constructors

            internal SyncList(<%= ClassName %> collection):
                base(Tag.Default) {

                this._root = collection.SyncRoot;
                this._collection = collection;
            }

            #endregion
            #region Protected Properties

            protected override <%= ItemType %>[] InnerArray {
                get { lock (this._root) return this._collection.InnerArray; }
            }

            #endregion
            #region Public Properties

            public override int Capacity {
                get { lock (this._root) return this._collection.Capacity; }
                set { lock (this._root) this._collection.Capacity = value; }
            }

            public override int Count {
                get { lock (this._root) return this._collection.Count; }
            }

            public override bool IsFixedSize {
                get { return this._collection.IsFixedSize; }
            }

            public override bool IsReadOnly {
                get { return this._collection.IsReadOnly; }
            }

            public override bool IsSynchronized {
                get { return true; }
            }

            public override bool IsUnique {
                get { return this._collection.IsUnique; }
            }

            public override <%= ItemType %> this[int index] {
                get { lock (this._root) return this._collection[index]; }
                set { lock (this._root) this._collection[index] = value;  }
            }

            public override object SyncRoot {
                get { return this._root; }
            }

            #endregion
            #region Public Methods

            public override int Add(<%= ItemType %> value) {
                lock (this._root) return this._collection.Add(value);
            }

            public override void AddRange(<%= ClassName %> collection) {
                lock (this._root) this._collection.AddRange(collection);
            }

            public override void AddRange(<%= ItemType %>[] array) {
                lock (this._root) this._collection.AddRange(array);
            }

            public override int BinarySearch(<%= ItemType %> value) {
                lock (this._root) return this._collection.BinarySearch(value);
            }

            public override void Clear() {
                lock (this._root) this._collection.Clear();
            }

            public override object Clone() {
                lock (this._root)
                    return new SyncList((<%= ClassName %>) this._collection.Clone());
            }
            <% if (DeepCopy) { %>

            public override <%= ClassName %> Copy() {
                lock (this._root) return this._collection.Copy();
            }
            <% } %>

            public override void CopyTo(<%= ItemType %>[] array) {
                lock (this._root) this._collection.CopyTo(array);
            }

            public override void CopyTo(<%= ItemType %>[] array, int arrayIndex) {
                lock (this._root) this._collection.CopyTo(array, arrayIndex);
            }
            <% if (IsKeyDefined()) { %>

            public override <%= ItemType %> GetByKey(<%= KeyType %> key) {
                lock (this._root) return this._collection.GetByKey(key);
            }
            <% } %>

            public override I<%= ItemType %>Enumerator GetEnumerator() {
                lock (this._root) return this._collection.GetEnumerator();
            }

            public override int IndexOf(<%= ItemType %> value) {
                lock (this._root) return this._collection.IndexOf(value);
            }
            <% if (IsKeyDefined()) { %>

            public override int IndexOfKey(<%= KeyType %> key) {
                lock (this._root) return this._collection.IndexOfKey(key);
            }
            <% } %>

            public override void Insert(int index, <%= ItemType %> value) {
                lock (this._root) this._collection.Insert(index, value);
            }

            public override void Remove(<%= ItemType %> value) {
                lock (this._root) this._collection.Remove(value);
            }

            public override void RemoveAt(int index) {
                lock (this._root) this._collection.RemoveAt(index);
            }

            public override void RemoveRange(int index, int count) {
                lock (this._root) this._collection.RemoveRange(index, count);
            }

            public override void Reverse() {
                lock (this._root) this._collection.Reverse();
            }

            public override void Reverse(int index, int count) {
                lock (this._root) this._collection.Reverse(index, count);
            }

            public override void Sort() {
                lock (this._root) this._collection.Sort();
            }

            public override void Sort(IComparer comparer) {
                lock (this._root) this._collection.Sort(comparer);
            }

            public override void Sort(int index, int count, IComparer comparer) {
                lock (this._root) this._collection.Sort(index, count, comparer);
            }

            public override <%= ItemType %>[] ToArray() {
                lock (this._root) return this._collection.ToArray();
            }

            public override void TrimToSize() {
                lock (this._root) this._collection.TrimToSize();
            }

            #endregion
        }

        #endregion
        #region Class UniqueList

        [Serializable]
        private sealed class UniqueList: <%= ClassName %> {
            #region Private Fields

            private <%= ClassName %> _collection;

            #endregion
            #region Internal Constructors

            internal UniqueList(<%= ClassName %> collection):
                base(Tag.Default) {
                this._collection = collection;
            }

            #endregion
            #region Protected Properties

            protected override <%= ItemType %>[] InnerArray {
                get { return this._collection.InnerArray; }
            }

            #endregion
            #region Public Properties

            public override int Capacity {
                get { return this._collection.Capacity; }
                set { this._collection.Capacity = value; }
            }

            public override int Count {
                get { return this._collection.Count; }
            }

            public override bool IsFixedSize {
                get { return this._collection.IsFixedSize; }
            }

            public override bool IsReadOnly {
                get { return this._collection.IsReadOnly; }
            }

            public override bool IsSynchronized {
                get { return this._collection.IsSynchronized; }
            }

            public override bool IsUnique {
                get { return true; }
            }

            public override <%= ItemType %> this[int index] {
                get { return this._collection[index]; }
                set {
                    CheckUnique(index, value);
                    this._collection[index] = value;
                }
            }

            public override object SyncRoot {
                get { return this._collection.SyncRoot; }
            }

            #endregion
            #region Public Methods

            public override int Add(<%= ItemType %> value) {
                CheckUnique(value);
                return this._collection.Add(value);
            }

            public override void AddRange(<%= ClassName %> collection) {
                foreach (<%= ItemType %> value in collection)
                    CheckUnique(value);
           
                this._collection.AddRange(collection);
            }

            public override void AddRange(<%= ItemType %>[] array) {
                foreach (<%= ItemType %> value in array)
                    CheckUnique(value);
           
                this._collection.AddRange(array);
            }

            public override int BinarySearch(<%= ItemType %> value) {
                return this._collection.BinarySearch(value);
            }

            public override void Clear() {
                this._collection.Clear();
            }

            public override object Clone() {
                return new UniqueList((<%= ClassName %>) this._collection.Clone());
            }
            <% if (DeepCopy) { %>

            public override <%= ClassName %> Copy() {
                return this._collection.Copy();
            }
            <% } %>

            public override void CopyTo(<%= ItemType %>[] array) {
                this._collection.CopyTo(array);
            }

            public override void CopyTo(<%= ItemType %>[] array, int arrayIndex) {
                this._collection.CopyTo(array, arrayIndex);
            }
            <% if (IsKeyDefined()) { %>

            public override <%= ItemType %> GetByKey(<%= KeyType %> key) {
                return this._collection.GetByKey(key);
            }
            <% } %>

            public override I<%= ItemType %>Enumerator GetEnumerator() {
                return this._collection.GetEnumerator();
            }

            public override int IndexOf(<%= ItemType %> value) {
                return this._collection.IndexOf(value);
            }
            <% if (IsKeyDefined()) { %>

            public override int IndexOfKey(<%= KeyType %> key) {
                return this._collection.IndexOfKey(key);
            }
            <% } %>

            public override void Insert(int index, <%= ItemType %> value) {
                CheckUnique(value);
                this._collection.Insert(index, value);
            }

            public override void Remove(<%= ItemType %> value) {
                this._collection.Remove(value);
            }

            public override void RemoveAt(int index) {
                this._collection.RemoveAt(index);
            }

            public override void RemoveRange(int index, int count) {
                this._collection.RemoveRange(index, count);
            }

            public override void Reverse() {
                this._collection.Reverse();
            }

            public override void Reverse(int index, int count) {
                this._collection.Reverse(index, count);
            }

            public override void Sort() {
                this._collection.Sort();
            }

            public override void Sort(IComparer comparer) {
                this._collection.Sort(comparer);
            }

            public override void Sort(int index, int count, IComparer comparer) {
                this._collection.Sort(index, count, comparer);
            }

            public override <%= ItemType %>[] ToArray() {
                return this._collection.ToArray();
            }

            public override void TrimToSize() {
                this._collection.TrimToSize();
            }

            #endregion
            #region Private Methods

            private void CheckUnique(<%= ItemType %> value) {
                if (IndexOf(value) >= 0)
                    throw new NotSupportedException(
                        "Unique collections cannot contain duplicate elements.");
            }

            private void CheckUnique(int index, <%= ItemType %> value) {
                int existing = IndexOf(value);
                if (existing >= 0 && existing != index)
                    throw new NotSupportedException(
                        "Unique collections cannot contain duplicate elements.");
            }

            #endregion
        }

        #endregion
  
  
  #region IBindingList Members

  public bool AllowNew {
   get {
    return true;
   }
  }
  public bool AllowRemove {
   get { return true;}
  }

 private ListChangedEventHandler onListChanged;
  public event ListChangedEventHandler ListChanged
    {
        add
        {
            onListChanged += value;
        }
        remove
        {
            onListChanged -= value;
        }
    }

  protected virtual void OnListChanged(ListChangedType lct,int newIdx){
   if (onListChanged != null)
   {
    ListChangedEventArgs lcea = new ListChangedEventArgs(lct,newIdx);
    onListChanged(this,lcea);
   }
  }


  public bool SupportsChangeNotification {
   get {
    return true;
   }
  }
  public object AddNew() {
   <%= ItemType %>  item  = new <%= ItemType %>();
   this.Add(item);
   return item;
  }

  public bool AllowEdit {
   get {
    return true;
   }
  }

  #region Unsupported

public bool SupportsSorting {
   get {    return false;   }
  }
  public void AddIndex(System.ComponentModel.PropertyDescriptor property) { throw new NotSupportedException(); }

  public void ApplySort(System.ComponentModel.PropertyDescriptor property, System.ComponentModel.ListSortDirection direction) {  throw new NotSupportedException();  }
  public System.ComponentModel.PropertyDescriptor SortProperty {
   get {    throw new NotSupportedException();   }
  }

  public int Find(System.ComponentModel.PropertyDescriptor property, object key) {   throw new NotSupportedException();  }

  public bool IsSorted {
   get {   throw new NotSupportedException();   }
  }

  public bool SupportsSearching {
   get {
    return false;
   }
 }
  public System.ComponentModel.ListSortDirection SortDirection {
   get {
    return new System.ComponentModel.ListSortDirection ();
   }
  }
  public void RemoveSort() {
   throw new NotSupportedException();
  }
  public void RemoveIndex(System.ComponentModel.PropertyDescriptor property) {
   throw new NotSupportedException();
  }
#endregion
  #endregion

  
  
    }

    #endregion
<% EndNamespace(TargetNamespace); %>
 

原创粉丝点击