using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Runtime.Serialization; using System.Text; namespace System.Collections.ObjectModel { [Serializable(), DebuggerDisplay("Count = {Count}")] public class ReadOnlySet : ISet, ISerializable, IDeserializationCallback { private ISet set; public ReadOnlySet(ISet set) { this.set = set; } #region ISet Members public bool Add(T item) { throw new NotSupportedException(); } public void ExceptWith(IEnumerable other) { throw new NotSupportedException(); } public void SymmetricExceptWith(IEnumerable other) { throw new NotSupportedException(); } public void IntersectWith(IEnumerable other) { throw new NotSupportedException(); } public void UnionWith(IEnumerable other) { throw new NotSupportedException(); } public bool IsProperSubsetOf(IEnumerable other) { return this.set.IsProperSubsetOf(other); } public bool IsProperSupersetOf(IEnumerable other) { return this.set.IsProperSupersetOf(other); } public bool IsSubsetOf(IEnumerable other) { return this.set.IsSubsetOf(other); } public bool IsSupersetOf(IEnumerable other) { return this.set.IsSupersetOf(other); } public bool Overlaps(IEnumerable other) { return this.set.Overlaps(other); } public bool SetEquals(IEnumerable other) { return this.set.SetEquals(other); } #endregion #region ICollection Members public int Count { get { return this.set.Count; } } public bool IsReadOnly { get { return true; } } void ICollection.Add(T item) { throw new NotSupportedException(); } public bool Remove(T item) { throw new NotSupportedException(); } public void Clear() { throw new NotSupportedException(); } public bool Contains(T item) { return this.set.Contains(item); } public void CopyTo(T[] array, int arrayIndex) { this.set.CopyTo(array, arrayIndex); } #endregion #region IEnumerable Members public IEnumerator GetEnumerator() { return ((IEnumerable)this.set).GetEnumerator(); } #endregion #region IEnumerable Members IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable)this.set).GetEnumerator(); } #endregion #region ISerializable Members void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context) { ((ISerializable)this.set).GetObjectData(info, context); } #endregion #region IDeserializationCallback Members void IDeserializationCallback.OnDeserialization(object sender) { ((IDeserializationCallback)this.set).OnDeserialization(sender); } #endregion } }