using System; using System.Collections; // Generated with CodeSmith namespace IBatisNet.DataAccess.Test.Domain { #region Interface IAccountCollection /// /// Defines size, enumerators, and synchronization methods for strongly /// typed collections of elements. /// /// /// IAccountCollection provides an /// that is strongly typed for elements. /// public interface IAccountCollection { #region Properties #region Count /// /// Gets the number of elements contained in the /// . /// /// The number of elements contained in the /// . /// Please refer to for details. int Count { get; } #endregion #region IsSynchronized /// /// Gets a value indicating whether access to the /// is synchronized (thread-safe). /// /// true if access to the is /// synchronized (thread-safe); otherwise, false. The default is false. /// Please refer to for details. bool IsSynchronized { get; } #endregion #region SyncRoot /// /// Gets an object that can be used to synchronize access /// to the . /// /// An object that can be used to synchronize access /// to the . /// Please refer to for details. object SyncRoot { get; } #endregion #endregion #region Methods #region CopyTo /// /// Copies the entire to a one-dimensional /// of elements, starting at the specified index of the target array. /// /// The one-dimensional that is the destination of the /// elements copied from the . /// The Array must have zero-based indexing. /// The zero-based index in /// at which copying begins. /// /// is a null reference. /// /// is less than zero. /// /// is equal to or greater than the length of . /// -or- /// The number of elements in the source is greater /// than the available space from to the end of the destination /// . /// Please refer to for details. void CopyTo(Account[] array, int arrayIndex); #endregion #region GetEnumerator /// /// Returns an that can /// iterate through the . /// /// An /// for the entire . /// Please refer to for details. IAccountEnumerator GetEnumerator(); #endregion #endregion } #endregion #region Interface IAccountList /// /// Represents a strongly typed collection of /// objects that can be individually accessed by index. /// /// /// IAccountList provides an /// that is strongly typed for elements. /// public interface IAccountList: IAccountCollection { #region Properties #region IsFixedSize /// /// Gets a value indicating whether the has a fixed size. /// /// true if the has a fixed size; /// otherwise, false. The default is false. /// Please refer to for details. bool IsFixedSize { get; } #endregion #region IsReadOnly /// /// Gets a value indicating whether the is read-only. /// /// true if the is read-only; /// otherwise, false. The default is false. /// Please refer to for details. bool IsReadOnly { get; } #endregion #region Item /// /// Gets or sets the element at the specified index. /// /// The zero-based index of the /// element to get or set. /// /// The element at the specified . /// /// /// is less than zero. /// -or- /// is equal to or greater than /// . /// /// /// The property is set and the is read-only. /// Please refer to for details. Account this[int index] { get; set; } #endregion #endregion #region Methods #region Add /// /// Adds a to the end /// of the . /// /// The object /// to be added to the end of the . /// This argument can be a null reference. /// /// The index at which /// the has been added. /// /// The is read-only. /// -or- /// The IAccountList has a fixed size. /// Please refer to for details. int Add(Account value); #endregion #region Clear /// /// Removes all elements from the . /// /// /// The is read-only. /// -or- /// The IAccountList has a fixed size. /// Please refer to for details. void Clear(); #endregion #region Contains /// /// Determines whether the /// contains the specified element. /// /// The object /// to locate in the . /// This argument can be a null reference. /// /// true if is found in the /// ; otherwise, false. /// Please refer to for details. bool Contains(Account value); #endregion #region IndexOf /// /// Returns the zero-based index of the first occurrence of the specified /// in the . /// /// The object /// to locate in the . /// This argument can be a null reference. /// /// /// The zero-based index of the first occurrence of /// in the , if found; otherwise, -1. /// /// Please refer to for details. int IndexOf(Account value); #endregion #region Insert /// /// Inserts a element into the /// at the specified index. /// /// The zero-based index at which /// should be inserted. /// The object /// to insert into the . /// This argument can be a null reference. /// /// /// is less than zero. /// -or- /// is greater than /// . /// /// /// The is read-only. /// -or- /// The IAccountList has a fixed size. /// Please refer to for details. void Insert(int index, Account value); #endregion #region Remove /// /// Removes the first occurrence of the specified /// from the . /// /// The object /// to remove from the . /// This argument can be a null reference. /// /// /// The is read-only. /// -or- /// The IAccountList has a fixed size. /// Please refer to for details. void Remove(Account value); #endregion #region RemoveAt /// /// Removes the element at the specified index of the /// . /// /// The zero-based index of the element to remove. /// /// is less than zero. /// -or- /// is equal to or greater than /// . /// /// /// The is read-only. /// -or- /// The IAccountList has a fixed size. /// Please refer to for details. void RemoveAt(int index); #endregion #endregion } #endregion #region Interface IAccountEnumerator /// /// Supports type-safe iteration over a collection that /// contains elements. /// /// /// IAccountEnumerator provides an /// that is strongly typed for elements. /// public interface IAccountEnumerator { #region Properties #region Current /// /// Gets the current element in the collection. /// /// The current element in the collection. /// The enumerator is positioned /// before the first element of the collection or after the last element. /// -or- /// The collection was modified after the enumerator was created. /// Please refer to for details, but note /// that Current fails if the collection was modified since the last successful /// call to or . Account Current { get; } #endregion #endregion #region Methods #region MoveNext /// /// Advances the enumerator to the next element of the collection. /// /// true if the enumerator was successfully advanced to the next element; /// false if the enumerator has passed the end of the collection. /// /// The collection was modified after the enumerator was created. /// Please refer to for details. bool MoveNext(); #endregion #region Reset /// /// Sets the enumerator to its initial position, /// which is before the first element in the collection. /// /// /// The collection was modified after the enumerator was created. /// Please refer to for details. void Reset(); #endregion #endregion } #endregion #region Class AccountCollection /// /// Implements a strongly typed collection of elements. /// /// /// AccountCollection provides an /// that is strongly typed for elements. /// [Serializable] public class AccountCollection: IAccountList, IList, ICloneable { #region Private Fields private const int _defaultCapacity = 16; private Account[] _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 AccountCollection(Tag tag) { } #endregion #region Public Constructors #region AccountCollection() /// /// Initializes a new instance of the class. /// /// /// Initializes a new instance of the class /// that is empty and has the default initial capacity. /// /// Please refer to for details. public AccountCollection() { this._array = new Account[_defaultCapacity]; } #endregion #region AccountCollection(Int32) /// /// Initializes a new instance of the class /// that is empty and has the specified initial capacity. /// /// The number of elements that the new /// is initially capable of storing. /// /// is less than zero. /// Please refer to for details. public AccountCollection(int capacity) { if (capacity < 0) throw new ArgumentOutOfRangeException("capacity", capacity, "Argument cannot be negative."); this._array = new Account[capacity]; } #endregion #region AccountCollection(AccountCollection) /// /// Initializes a new instance of the class /// that contains elements copied from the specified collection and /// that has the same initial capacity as the number of elements copied. /// /// The /// whose elements are copied to the new collection. /// /// is a null reference. /// Please refer to for details. public AccountCollection(AccountCollection collection) { if (collection == null) throw new ArgumentNullException("collection"); this._array = new Account[collection.Count]; AddRange(collection); } #endregion #region AccountCollection(Account[]) /// /// Initializes a new instance of the class /// that contains elements copied from the specified /// array and that has the same initial capacity as the number of elements copied. /// /// An of /// elements that are copied to the new collection. /// /// is a null reference. /// Please refer to for details. public AccountCollection(Account[] array) { if (array == null) throw new ArgumentNullException("array"); this._array = new Account[array.Length]; AddRange(array); } #endregion #endregion #region Protected Properties #region InnerArray /// /// Gets the list of elements contained in the instance. /// /// /// A one-dimensional with zero-based indexing that contains all /// elements in the . /// /// /// Use InnerArray to access the element array of a /// 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. /// protected virtual Account[] InnerArray { get { return this._array; } } #endregion #endregion #region Public Properties #region Capacity /// /// Gets or sets the capacity of the . /// /// The number of elements that the /// can contain. /// /// Capacity is set to a value that is less than . /// Please refer to for details. 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 Account[_defaultCapacity]; return; } Account[] newArray = new Account[value]; Array.Copy(this._array, newArray, this._count); this._array = newArray; } } #endregion #region Count /// /// Gets the number of elements contained in the . /// /// /// The number of elements contained in the . /// /// Please refer to for details. public virtual int Count { get { return this._count; } } #endregion #region IsFixedSize /// /// Gets a value indicating whether the has a fixed size. /// /// true if the has a fixed size; /// otherwise, false. The default is false. /// Please refer to for details. public virtual bool IsFixedSize { get { return false; } } #endregion #region IsReadOnly /// /// Gets a value indicating whether the is read-only. /// /// true if the is read-only; /// otherwise, false. The default is false. /// Please refer to for details. public virtual bool IsReadOnly { get { return false; } } #endregion #region IsSynchronized /// /// Gets a value indicating whether access to the /// is synchronized (thread-safe). /// /// true if access to the is /// synchronized (thread-safe); otherwise, false. The default is false. /// Please refer to for details. public virtual bool IsSynchronized { get { return false; } } #endregion #region IsUnique /// /// Gets a value indicating whether the /// ensures that all elements are unique. /// /// /// true if the ensures that all /// elements are unique; otherwise, false. The default is false. /// /// /// IsUnique returns true exactly if the /// is exposed through a wrapper. /// Please refer to for details. /// public virtual bool IsUnique { get { return false; } } #endregion #region Item: Account /// /// Gets or sets the element at the specified index. /// /// The zero-based index of the /// element to get or set. /// /// The element at the specified . /// /// /// is less than zero. /// -or- /// is equal to or greater than . /// /// /// The property is set and the is read-only. /// -or- /// The property is set, the AccountCollection already contains the /// specified element at a different index, and the AccountCollection /// ensures that all elements are unique. /// Please refer to for details. public virtual Account this[int index] { get { ValidateIndex(index); return this._array[index]; } set { ValidateIndex(index); ++this._version; this._array[index] = value; } } #endregion #region IList.Item: Object /// /// Gets or sets the element at the specified index. /// /// The zero-based index of the element to get or set. /// /// The element at the specified . When the property /// is set, this value must be compatible with . /// /// /// is less than zero. /// -or- /// is equal to or greater than . /// /// The property is set to a value /// that is not compatible with . /// /// The property is set and the is read-only. /// -or- /// The property is set, the AccountCollection already contains the /// specified element at a different index, and the AccountCollection /// ensures that all elements are unique. /// Please refer to for details. object IList.this[int index] { get { return this[index]; } set { this[index] = (Account) value; } } #endregion #region SyncRoot /// /// Gets an object that can be used to synchronize /// access to the . /// /// An object that can be used to synchronize /// access to the . /// /// Please refer to for details. public virtual object SyncRoot { get { return this; } } #endregion #endregion #region Public Methods #region Add(Account) /// /// Adds a to the end of the . /// /// The object /// to be added to the end of the . /// This argument can be a null reference. /// /// The index at which the /// has been added. /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// -or- /// The AccountCollection already contains the specified /// , and the AccountCollection /// ensures that all elements are unique. /// Please refer to for details. public virtual int Add(Account value) { if (this._count == this._array.Length) EnsureCapacity(this._count + 1); ++this._version; this._array[this._count] = value; return this._count++; } #endregion #region IList.Add(Object) /// /// Adds an to the end of the . /// /// /// The object to be added to the end of the . /// This argument must be compatible with . /// This argument can be a null reference. /// /// The index at which the /// has been added. /// /// is not compatible with . /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// -or- /// The AccountCollection already contains the specified /// , and the AccountCollection /// ensures that all elements are unique. /// Please refer to for details. int IList.Add(object value) { return Add((Account) value); } #endregion #region AddRange(AccountCollection) /// /// Adds a range of elements to the end of the . /// /// /// Adds the elements of another collection to the end of the . /// /// The whose elements /// should be added to the end of the current collection. /// /// is a null reference. /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// -or- /// The AccountCollection already contains one or more elements /// in the specified , and the AccountCollection /// ensures that all elements are unique. /// Please refer to for details. public virtual void AddRange(AccountCollection 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); this._count += collection.Count; } #endregion #region AddRange(Account[]) /// /// Adds the elements of a array /// to the end of the . /// /// An of elements /// that should be added to the end of the . /// /// is a null reference. /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// -or- /// The AccountCollection already contains one or more elements /// in the specified , and the AccountCollection /// ensures that all elements are unique. /// Please refer to for details. public virtual void AddRange(Account[] 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); this._count += array.Length; } #endregion #region BinarySearch /// /// Searches the entire sorted for an /// element using the default comparer /// and returns the zero-based index of the element. /// /// The object /// to locate in the . /// This argument can be a null reference. /// /// The zero-based index of in the sorted /// , if is found; /// otherwise, a negative number, which is the bitwise complement of the index /// of the next element that is larger than or, if there /// is no larger element, the bitwise complement of . /// /// Neither nor the elements of the /// implement the interface. /// Please refer to for details. public virtual int BinarySearch(Account value) { return Array.BinarySearch(this._array, 0, this._count, value); } #endregion #region Clear /// /// Removes all elements from the . /// /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// Please refer to for details. public virtual void Clear() { if (this._count == 0) return; ++this._version; Array.Clear(this._array, 0, this._count); this._count = 0; } #endregion #region Clone /// /// Creates a shallow copy of the . /// /// A shallow copy of the . /// Please refer to for details. public virtual object Clone() { AccountCollection collection = new AccountCollection(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(Account) /// /// Determines whether the /// contains the specified element. /// /// The object /// to locate in the . /// This argument can be a null reference. /// /// true if is found in the /// ; otherwise, false. /// Please refer to for details. public bool Contains(Account value) { return (IndexOf(value) >= 0); } #endregion #region IList.Contains(Object) /// /// Determines whether the contains the specified element. /// /// The object to locate in the . /// This argument must be compatible with . /// This argument can be a null reference. /// /// true if is found in the /// ; otherwise, false. /// /// is not compatible with . /// Please refer to for details. bool IList.Contains(object value) { return Contains((Account) value); } #endregion #region CopyTo(Account[]) /// /// Copies the or a portion of it to a one-dimensional array. /// /// /// Copies the entire to a one-dimensional /// of elements, starting at the beginning of the target array. /// /// The one-dimensional that is the destination of the /// elements copied from the . /// The Array must have zero-based indexing. /// /// is a null reference. /// /// The number of elements in the source is greater /// than the available space in the destination . /// Please refer to for details. public virtual void CopyTo(Account[] array) { CheckTargetArray(array, 0); Array.Copy(this._array, array, this._count); } #endregion #region CopyTo(Account[], Int32) /// /// Copies the entire to a one-dimensional /// of elements, starting at the specified index of the target array. /// /// The one-dimensional that is the destination of the /// elements copied from the . /// The Array must have zero-based indexing. /// The zero-based index in /// at which copying begins. /// /// is a null reference. /// /// is less than zero. /// /// is equal to or greater than the length of . /// -or- /// The number of elements in the source is greater than the /// available space from to the end of the destination /// . /// Please refer to for details. public virtual void CopyTo(Account[] array, int arrayIndex) { CheckTargetArray(array, arrayIndex); Array.Copy(this._array, 0, array, arrayIndex, this._count); } #endregion #region ICollection.CopyTo(Array, Int32) /// /// Copies the entire to a one-dimensional , /// starting at the specified index of the target array. /// /// The one-dimensional that is the destination of the /// elements copied from the . /// The Array must have zero-based indexing. /// The zero-based index in /// at which copying begins. /// /// is a null reference. /// /// is less than zero. /// /// is multidimensional. /// -or- /// is equal to or greater than the length of . /// -or- /// The number of elements in the source is greater than the /// available space from to the end of the destination /// . /// /// The type cannot be cast automatically /// to the type of the destination . /// Please refer to for details. void ICollection.CopyTo(Array array, int arrayIndex) { CopyTo((Account[]) array, arrayIndex); } #endregion #region GetEnumerator: IAccountEnumerator /// /// Returns an that can /// iterate through the . /// /// An /// for the entire . /// Please refer to for details. public virtual IAccountEnumerator GetEnumerator() { return new Enumerator(this); } #endregion #region IEnumerable.GetEnumerator: IEnumerator /// /// Returns an that can /// iterate through the . /// /// An /// for the entire . /// Please refer to for details. IEnumerator IEnumerable.GetEnumerator() { return (IEnumerator) GetEnumerator(); } #endregion #region IndexOf(Account) /// /// Returns the zero-based index of the first occurrence of the specified /// in the . /// /// The object /// to locate in the . /// This argument can be a null reference. /// /// /// The zero-based index of the first occurrence of /// in the , if found; otherwise, -1. /// /// Please refer to for details. public virtual int IndexOf(Account value) { return Array.IndexOf(this._array, value, 0, this._count); } #endregion #region IList.IndexOf(Object) /// /// Returns the zero-based index of the first occurrence of the specified /// in the . /// /// The object to locate in the . /// This argument must be compatible with . /// This argument can be a null reference. /// /// /// The zero-based index of the first occurrence of /// in the , if found; otherwise, -1. /// /// /// is not compatible with . /// Please refer to for details. int IList.IndexOf(object value) { return IndexOf((Account) value); } #endregion #region Insert(Int32, Account) /// /// Inserts a element into the /// at the specified index. /// /// The zero-based index at which /// should be inserted. /// The object /// to insert into the . /// This argument can be a null reference. /// /// /// is less than zero. /// -or- /// is greater than . /// /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// -or- /// The AccountCollection already contains the specified /// , and the AccountCollection /// ensures that all elements are unique. /// Please refer to for details. public virtual void Insert(int index, Account 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; } #endregion #region IList.Insert(Int32, Object) /// /// Inserts an element into the at the specified index. /// /// The zero-based index at which /// should be inserted. /// The object to insert into the . /// This argument must be compatible with . /// This argument can be a null reference. /// /// /// is less than zero. /// -or- /// is greater than . /// /// /// is not compatible with . /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// -or- /// The AccountCollection already contains the specified /// , and the AccountCollection /// ensures that all elements are unique. /// Please refer to for details. void IList.Insert(int index, object value) { Insert(index, (Account) value); } #endregion #region ReadOnly /// /// Returns a read-only wrapper for the specified . /// /// The to wrap. /// A read-only wrapper around . /// /// is a null reference. /// Please refer to for details. public static AccountCollection ReadOnly(AccountCollection collection) { if (collection == null) throw new ArgumentNullException("collection"); return new ReadOnlyList(collection); } #endregion #region Remove(Account) /// /// Removes the first occurrence of the specified /// from the . /// /// The object /// to remove from the . /// This argument can be a null reference. /// /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// Please refer to for details. public virtual void Remove(Account value) { int index = IndexOf(value); if (index >= 0) RemoveAt(index); } #endregion #region IList.Remove(Object) /// /// Removes the first occurrence of the specified /// from the . /// /// The object to remove from the . /// This argument must be compatible with . /// This argument can be a null reference. /// /// /// is not compatible with . /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// Please refer to for details. void IList.Remove(object value) { Remove((Account) value); } #endregion #region RemoveAt /// /// Removes the element at the specified index of the . /// /// The zero-based index of the element to remove. /// /// is less than zero. /// -or- /// is equal to or greater than . /// /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// Please refer to for details. 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); this._array[this._count] = null; } #endregion #region RemoveRange /// /// Removes the specified range of elements from the . /// /// The zero-based starting index of the range /// of elements to remove. /// The number of elements to remove. /// /// and do not denote a /// valid range of elements in the . /// /// is less than zero. /// -or- /// is less than zero. /// /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// Please refer to for details. 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); } #endregion #region Reverse() /// /// Reverses the order of the elements in the /// or a portion of it. /// /// /// Reverses the order of the elements in the entire . /// /// /// The is read-only. /// Please refer to for details. public virtual void Reverse() { if (this._count <= 1) return; ++this._version; Array.Reverse(this._array, 0, this._count); } #endregion #region Reverse(Int32, Int32) /// /// Reverses the order of the elements in the specified range. /// /// The zero-based starting index of the range /// of elements to reverse. /// The number of elements to reverse. /// /// and do not denote a /// valid range of elements in the . /// /// is less than zero. /// -or- /// is less than zero. /// /// /// The is read-only. /// Please refer to for details. 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); } #endregion #region Sort() /// /// Sorts the elements in the or a portion of it. /// /// /// Sorts the elements in the entire /// using the implementation of each element. /// /// /// The is read-only. /// Please refer to for details. public virtual void Sort() { if (this._count <= 1) return; ++this._version; Array.Sort(this._array, 0, this._count); } #endregion #region Sort(IComparer) /// /// Sorts the elements in the entire /// using the specified interface. /// /// /// The implementation to use when comparing elements. /// -or- /// A null reference to use the implementation /// of each element. /// /// The is read-only. /// Please refer to for details. public virtual void Sort(IComparer comparer) { if (this._count <= 1) return; ++this._version; Array.Sort(this._array, 0, this._count, comparer); } #endregion #region Sort(Int32, Int32, IComparer) /// /// Sorts the elements in the specified range /// using the specified interface. /// /// The zero-based starting index of the range /// of elements to sort. /// The number of elements to sort. /// /// The implementation to use when comparing elements. /// -or- /// A null reference to use the implementation /// of each element. /// /// and do not denote a /// valid range of elements in the . /// /// is less than zero. /// -or- /// is less than zero. /// /// /// The is read-only. /// Please refer to for details. 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); } #endregion #region Synchronized /// /// Returns a synchronized (thread-safe) wrapper /// for the specified . /// /// The to synchronize. /// /// A synchronized (thread-safe) wrapper around . /// /// /// is a null reference. /// Please refer to for details. public static AccountCollection Synchronized(AccountCollection collection) { if (collection == null) throw new ArgumentNullException("collection"); return new SyncList(collection); } #endregion #region ToArray /// /// Copies the elements of the to a new /// of elements. /// /// A one-dimensional of /// elements containing copies of the elements of the . /// Please refer to for details. public virtual Account[] ToArray() { Account[] array = new Account[this._count]; Array.Copy(this._array, array, this._count); return array; } #endregion #region TrimToSize /// /// Sets the capacity to the actual number of elements in the . /// /// /// The is read-only. /// -or- /// The AccountCollection has a fixed size. /// Please refer to for details. public virtual void TrimToSize() { Capacity = this._count; } #endregion #region Unique /// /// Returns a wrapper for the specified /// ensuring that all elements are unique. /// /// The to wrap. /// /// A wrapper around ensuring that all elements are unique. /// /// /// contains duplicate elements. /// /// is a null reference. /// /// The Unique wrapper provides a set-like collection by ensuring /// that all elements in the are unique. /// /// Unique raises an if the specified /// contains any duplicate elements. The returned /// wrapper raises a whenever the user attempts /// to add an element that is already contained in the AccountCollection. /// /// Note: The Unique wrapper reflects any changes made /// to the underlying , including the possible /// creation of duplicate elements. The uniqueness of all elements is therefore /// no longer assured if the underlying collection is manipulated directly. /// public static AccountCollection Unique(AccountCollection 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("collection", "Argument cannot contain duplicate elements."); 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 < 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: IAccountEnumerator, IEnumerator { #region Private Fields private readonly AccountCollection _collection; private readonly int _version; private int _index; #endregion #region Internal Constructors internal Enumerator(AccountCollection collection) { this._collection = collection; this._version = collection._version; this._index = -1; } #endregion #region Public Properties public Account 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: AccountCollection { #region Private Fields private AccountCollection _collection; #endregion #region Internal Constructors internal ReadOnlyList(AccountCollection collection): base(Tag.Default) { this._collection = collection; } #endregion #region Protected Properties protected override Account[] 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 Account 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(Account value) { throw new NotSupportedException( "Read-only collections cannot be modified."); } public override void AddRange(AccountCollection collection) { throw new NotSupportedException( "Read-only collections cannot be modified."); } public override void AddRange(Account[] array) { throw new NotSupportedException( "Read-only collections cannot be modified."); } public override int BinarySearch(Account 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((AccountCollection) this._collection.Clone()); } public override void CopyTo(Account[] array) { this._collection.CopyTo(array); } public override void CopyTo(Account[] array, int arrayIndex) { this._collection.CopyTo(array, arrayIndex); } public override IAccountEnumerator GetEnumerator() { return this._collection.GetEnumerator(); } public override int IndexOf(Account value) { return this._collection.IndexOf(value); } public override void Insert(int index, Account value) { throw new NotSupportedException( "Read-only collections cannot be modified."); } public override void Remove(Account 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 Account[] 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: AccountCollection { #region Private Fields private AccountCollection _collection; private object _root; #endregion #region Internal Constructors internal SyncList(AccountCollection collection): base(Tag.Default) { this._root = collection.SyncRoot; this._collection = collection; } #endregion #region Protected Properties protected override Account[] 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 Account 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(Account value) { lock (this._root) return this._collection.Add(value); } public override void AddRange(AccountCollection collection) { lock (this._root) this._collection.AddRange(collection); } public override void AddRange(Account[] array) { lock (this._root) this._collection.AddRange(array); } public override int BinarySearch(Account 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((AccountCollection) this._collection.Clone()); } public override void CopyTo(Account[] array) { lock (this._root) this._collection.CopyTo(array); } public override void CopyTo(Account[] array, int arrayIndex) { lock (this._root) this._collection.CopyTo(array, arrayIndex); } public override IAccountEnumerator GetEnumerator() { lock (this._root) return this._collection.GetEnumerator(); } public override int IndexOf(Account value) { lock (this._root) return this._collection.IndexOf(value); } public override void Insert(int index, Account value) { lock (this._root) this._collection.Insert(index, value); } public override void Remove(Account 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 Account[] 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: AccountCollection { #region Private Fields private AccountCollection _collection; #endregion #region Internal Constructors internal UniqueList(AccountCollection collection): base(Tag.Default) { this._collection = collection; } #endregion #region Protected Properties protected override Account[] 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 Account 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(Account value) { CheckUnique(value); return this._collection.Add(value); } public override void AddRange(AccountCollection collection) { foreach (Account value in collection) CheckUnique(value); this._collection.AddRange(collection); } public override void AddRange(Account[] array) { foreach (Account value in array) CheckUnique(value); this._collection.AddRange(array); } public override int BinarySearch(Account value) { return this._collection.BinarySearch(value); } public override void Clear() { this._collection.Clear(); } public override object Clone() { return new UniqueList((AccountCollection) this._collection.Clone()); } public override void CopyTo(Account[] array) { this._collection.CopyTo(array); } public override void CopyTo(Account[] array, int arrayIndex) { this._collection.CopyTo(array, arrayIndex); } public override IAccountEnumerator GetEnumerator() { return this._collection.GetEnumerator(); } public override int IndexOf(Account value) { return this._collection.IndexOf(value); } public override void Insert(int index, Account value) { CheckUnique(value); this._collection.Insert(index, value); } public override void Remove(Account 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 Account[] ToArray() { return this._collection.ToArray(); } public override void TrimToSize() { this._collection.TrimToSize(); } #endregion #region Private Methods private void CheckUnique(Account value) { if (IndexOf(value) >= 0) throw new NotSupportedException( "Unique collections cannot contain duplicate elements."); } private void CheckUnique(int index, Account value) { int existing = IndexOf(value); if (existing >= 0 && existing != index) throw new NotSupportedException( "Unique collections cannot contain duplicate elements."); } #endregion } #endregion } #endregion }