using System; using System.Collections.Generic; namespace Org.BouncyCastle.Utilities.Collections { internal abstract class ReadOnlySet : ISet { System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } public bool IsReadOnly => true; void ICollection.Add(T item) => throw new NotSupportedException(); public bool Add(T item) => throw new NotSupportedException(); public void Clear() => throw new NotSupportedException(); public void ExceptWith(IEnumerable other) => throw new NotSupportedException(); public void IntersectWith(IEnumerable other) => throw new NotSupportedException(); public bool Remove(T item) => throw new NotSupportedException(); public bool SetEquals(IEnumerable other) => throw new NotSupportedException(); public void SymmetricExceptWith(IEnumerable other) => throw new NotSupportedException(); public void UnionWith(IEnumerable other) => throw new NotSupportedException(); public abstract bool Contains(T item); public abstract void CopyTo(T[] array, int arrayIndex); public abstract int Count { get; } public abstract IEnumerator GetEnumerator(); public abstract bool IsProperSubsetOf(IEnumerable other); public abstract bool IsProperSupersetOf(IEnumerable other); public abstract bool IsSubsetOf(IEnumerable other); public abstract bool IsSupersetOf(IEnumerable other); public abstract bool Overlaps(IEnumerable other); } internal class ReadOnlySetProxy : ReadOnlySet { private readonly ISet m_target; internal ReadOnlySetProxy(ISet target) { if (target == null) throw new ArgumentNullException(nameof(target)); m_target = target; } public override bool Contains(T item) => m_target.Contains(item); public override void CopyTo(T[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex); public override int Count => m_target.Count; public override IEnumerator GetEnumerator() => m_target.GetEnumerator(); public override bool IsProperSubsetOf(IEnumerable other) => m_target.IsProperSubsetOf(other); public override bool IsProperSupersetOf(IEnumerable other) => m_target.IsProperSupersetOf(other); public override bool IsSubsetOf(IEnumerable other) => m_target.IsSubsetOf(other); public override bool IsSupersetOf(IEnumerable other) => m_target.IsSupersetOf(other); public override bool Overlaps(IEnumerable other) => m_target.Overlaps(other); } }