#region Apache License 2.0 /* Nuclex .NET Framework Copyright (C) 2002-2024 Markus Ewald / Nuclex Development Labs Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #endregion // Apache License 2.0 using System; using System.Threading; using System.Collections; using System.Collections.Generic; namespace Nuclex.Support.Collections { // More than 400 lines of code just to implement the .NET collection interfaces. // Shows the niceties of having to support languages without generics and using // an inferior design to make collections "more convenient" for the user :/ partial class TransformingReadOnlyCollection { #region IList Members /// /// Inserts an item to the TransformingReadOnlyCollection at the specified index. /// /// /// The zero-based index at which item should be inserted. /// /// /// The object to insert into the TransformingReadOnlyCollection /// /// /// The TransformingReadOnlyCollection is read-only. /// /// /// index is not a valid index in the TransformingReadOnlyCollection. /// void IList.Insert(int index, TExposedItem item) { throw new NotSupportedException("The collection is ready-only"); } /// /// Removes the TransformingReadOnlyCollection item at the specified index. /// /// The zero-based index of the item to remove. /// /// The TransformingReadOnlyCollection is read-only. /// /// /// Index is not a valid index in the TransformingReadOnlyCollection. /// void IList.RemoveAt(int index) { throw new NotSupportedException("The collection is ready-only"); } /// 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 index. /// /// Index is not a valid index in the TransformingReadOnlyCollection. /// /// /// The property is set and the TransformingReadOnlyCollection is read-only /// TExposedItem IList.this[int index] { get { return this[index]; } set { throw new NotSupportedException("The collection is ready-only"); } } #endregion #region ICollection Members /// Adds an item to the TransformingReadOnlyCollection. /// The object to add to the TransformingReadOnlyCollection /// /// The TransformingReadOnlyCollection is read-only. /// void ICollection.Add(TExposedItem item) { throw new NotSupportedException("The collection is ready-only"); } /// Removes all items from the TransformingReadOnlyCollection /// /// The TransformingReadOnlyCollection is read-only. /// void ICollection.Clear() { throw new NotSupportedException("The collection is ready-only"); } /// /// Removes the first occurrence of a specific object from the /// TransformingReadOnlyCollection. /// /// /// The object to remove from the TransformingReadOnlyCollection /// /// /// True if item was successfully removed from the TransformingReadOnlyCollection; /// otherwise, false. This method also returns false if item is not found in the /// original TransformingReadOnlyCollection. /// /// /// The TransformingReadOnlyCollection is read-only. /// bool ICollection.Remove(TExposedItem item) { throw new NotSupportedException("The collection is ready-only"); } #endregion #region IEnumerable Members /// Returns an enumerator that iterates through a collection. /// /// A System.Collections.IEnumerator object that can be used to iterate through /// the collection. /// IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } #endregion #region IList Members /// Adds an item to the TransformingReadOnlyCollection. /// /// The System.Object to add to the TransformingReadOnlyCollection. /// /// The position into which the new element was inserted. /// /// The System.Collections.IList is read-only or the TransformingReadOnlyCollection /// has a fixed size. /// int IList.Add(object value) { throw new NotSupportedException("The collection is ready-only"); } /// Removes all items from the TransformingReadOnlyCollection. /// /// The TransformingReadOnlyCollection is read-only. /// void IList.Clear() { throw new NotSupportedException("The collection is ready-only"); } /// /// Determines whether the TransformingReadOnlyCollection contains a specific value. /// /// /// The System.Object to locate in the TransformingReadOnlyCollection. /// /// /// True if the System.Object is found in the TransformingReadOnlyCollection; /// otherwise, false. /// bool IList.Contains(object value) { return Contains((TExposedItem)value); } /// /// Determines the index of a specific item in the TransformingReadOnlyCollection. /// /// /// The System.Object to locate in the TransformingReadOnlyCollection. /// /// /// The index of value if found in the list; otherwise, -1. /// int IList.IndexOf(object value) { return IndexOf((TExposedItem)value); } /// /// Inserts an item to the TransformingReadOnlyCollection at the specified index. /// /// /// The zero-based index at which value should be inserted. /// /// /// The System.Object to insert into the TransformingReadOnlyCollection. /// /// /// Index is not a valid index in the TransformingReadOnlyCollection. /// /// /// The System.Collections.IList is read-only or the TransformingReadOnlyCollection /// has a fixed size. /// /// /// Value is null reference in the TransformingReadOnlyCollection. /// void IList.Insert(int index, object value) { throw new NotSupportedException("The collection is ready-only"); } /// /// A value indicating whether the TransformingReadOnlyCollection has a fixed /// size. /// bool IList.IsFixedSize { get { return true; } } /// /// Removes the first occurrence of a specific object from the /// TransformingReadOnlyCollection. /// /// /// The System.Object to remove from the TransformingReadOnlyCollection. /// /// /// The TransformingReadOnlyCollection is read-only or the /// TransformingReadOnlyCollection has a fixed size. /// void IList.Remove(object value) { throw new NotSupportedException("The collection is ready-only"); } /// /// Removes the TransformingReadOnlyCollection item at the specified index. /// /// The zero-based index of the item to remove. /// /// Index is not a valid index in the TransformingReadOnlyCollection. /// /// /// The TransformingReadOnlyCollection is read-only or the /// TransformingReadOnlyCollection has a fixed size. /// void IList.RemoveAt(int index) { throw new NotSupportedException("The collection is ready-only"); } /// 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 index /// /// Index is not a valid index in the TransformingReadOnlyCollection /// /// /// The property is set and the TransformingReadOnlyCollection is read-only. /// object IList.this[int index] { get { return this[index]; } set { throw new NotSupportedException("The collection is ready-only"); } } #endregion #region ICollection Members /// /// Copies the elements of the TransformingReadOnlyCollection to an System.Array, /// starting at a particular System.Array index. /// /// /// The one-dimensional System.Array that is the destination of the elements /// copied from TransformingReadOnlyCollection. The System.Array must have zero-based /// indexing. /// /// The zero-based index in array at which copying begins. /// /// Array is null. /// /// /// Index is less than zero. /// /// /// Array is multidimensional or index is equal to or greater than the length /// of array or the number of elements in the source TransformingReadOnlyCollection /// is greater than the available space from index to the end of the destination /// array. /// /// /// The type of the source TransformingReadOnlyCollection cannot be cast /// automatically to the type of the destination array. /// void ICollection.CopyTo(Array array, int index) { CopyTo((TExposedItem[])array, index); } /// /// The number of elements contained in the TransformingReadOnlyCollection. /// int ICollection.Count { get { return Count; } } /// /// A value indicating whether access to the TransformingReadOnlyCollection /// is synchronized (thread safe). /// bool ICollection.IsSynchronized { get { return false; } } /// /// An object that can be used to synchronize access to the /// TransformingReadOnlyCollection. /// object ICollection.SyncRoot { get { if(this.syncRoot == null) { ICollection is2 = this.items as ICollection; if(is2 != null) { this.syncRoot = is2.SyncRoot; } else { Interlocked.CompareExchange(ref this.syncRoot, new object(), null); } } return this.syncRoot; } } #endregion } } // namespace Nuclex.Support.Collections