using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace System.Unicode { /// Represents a collection of code point cross-references. public struct UnicodeCrossReferenceCollection : IList { private static int[] EmptyArray = new int[0]; /// Represents an enumerator for the class. public struct Enumerator : IEnumerator { private readonly int[] items; private int index; /// Initializes a new instance of the struct. /// The items to enumerate. internal Enumerator(int[] items) { this.items = items; this.index = -1; } /// Does nothing. public void Dispose() { } /// Gets the element in the collection at the current position of the enumerator.. /// The element in the collection at the current position of the enumerator. public int Current { get { return items[index]; } } object IEnumerator.Current { get { return Current; } } /// 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. public bool MoveNext() { return index < items.Length && ++index < items.Length; } void IEnumerator.Reset() { this.index = -1; } } /// Gets an empty struct. public static readonly UnicodeCrossReferenceCollection Empty = new UnicodeCrossReferenceCollection(EmptyArray); private readonly int[] items; internal UnicodeCrossReferenceCollection(int[] items) { this.items = items ?? EmptyArray; } /// Gets the cross-referenced code point at the specified index. /// The cross-referenced code point. /// The index. /// The cross-referenced code point at the specified index. public int this[int index] { get { return items[index]; } } int IList.this[int index] { get { return items[index]; } set { throw new NotSupportedException(); } } /// Gets the number of elements contained in the . /// The number of elements contained in the . public int Count { get { return items.Length; } } bool ICollection.IsReadOnly { get { return true; } } void ICollection.Add(int item) { throw new NotSupportedException(); } void IList.Insert(int index, int item) { throw new NotSupportedException(); } bool ICollection.Remove(int item) { throw new NotSupportedException(); } void IList.RemoveAt(int index) { throw new NotSupportedException(); } void ICollection.Clear() { throw new NotSupportedException(); } /// Determines the index of a specific item in the . /// The object to locate in the . /// The index of the item if found in the list; otherwise, -1. public int IndexOf(int item) { return Array.IndexOf(items, item); } /// Determines whether the contains a specific value. /// The object to locate in the . /// if item is fount in the ; otherwise. public bool Contains(int item) { return IndexOf(item) >= 0; } /// /// Copies the elements of the UnicodeCrossReferenceCollection to an , starting at a particular index. /// /// The one-dimensional that is the destination of the elements to copy from UnicodeCrossReferenceCollection. The must have zero-based indexing. /// The zeo-based index in array at which copy begins. public void CopyTo(int[] array, int arrayIndex) { items.CopyTo(array, arrayIndex); } /// Returns an enumerator that iterates through the collection. /// A that can be used to iterate through the collection. public Enumerator GetEnumerator() { return new Enumerator(items); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } } }