ReadOnlySet.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Collections.Generic;
  5. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Utilities.Collections
  6. {
  7. internal abstract class ReadOnlySet<T>
  8. : ISet<T>
  9. {
  10. System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
  11. {
  12. return GetEnumerator();
  13. }
  14. public bool IsReadOnly => true;
  15. void ICollection<T>.Add(T item) => throw new NotSupportedException();
  16. public bool Add(T item) => throw new NotSupportedException();
  17. public void Clear() => throw new NotSupportedException();
  18. public void ExceptWith(IEnumerable<T> other) => throw new NotSupportedException();
  19. public void IntersectWith(IEnumerable<T> other) => throw new NotSupportedException();
  20. public bool Remove(T item) => throw new NotSupportedException();
  21. public bool SetEquals(IEnumerable<T> other) => throw new NotSupportedException();
  22. public void SymmetricExceptWith(IEnumerable<T> other) => throw new NotSupportedException();
  23. public void UnionWith(IEnumerable<T> other) => throw new NotSupportedException();
  24. public abstract bool Contains(T item);
  25. public abstract void CopyTo(T[] array, int arrayIndex);
  26. public abstract int Count { get; }
  27. public abstract IEnumerator<T> GetEnumerator();
  28. public abstract bool IsProperSubsetOf(IEnumerable<T> other);
  29. public abstract bool IsProperSupersetOf(IEnumerable<T> other);
  30. public abstract bool IsSubsetOf(IEnumerable<T> other);
  31. public abstract bool IsSupersetOf(IEnumerable<T> other);
  32. public abstract bool Overlaps(IEnumerable<T> other);
  33. }
  34. internal class ReadOnlySetProxy<T>
  35. : ReadOnlySet<T>
  36. {
  37. private readonly ISet<T> m_target;
  38. internal ReadOnlySetProxy(ISet<T> target)
  39. {
  40. if (target == null)
  41. throw new ArgumentNullException(nameof(target));
  42. m_target = target;
  43. }
  44. public override bool Contains(T item) => m_target.Contains(item);
  45. public override void CopyTo(T[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex);
  46. public override int Count => m_target.Count;
  47. public override IEnumerator<T> GetEnumerator() => m_target.GetEnumerator();
  48. public override bool IsProperSubsetOf(IEnumerable<T> other) => m_target.IsProperSubsetOf(other);
  49. public override bool IsProperSupersetOf(IEnumerable<T> other) => m_target.IsProperSupersetOf(other);
  50. public override bool IsSubsetOf(IEnumerable<T> other) => m_target.IsSubsetOf(other);
  51. public override bool IsSupersetOf(IEnumerable<T> other) => m_target.IsSupersetOf(other);
  52. public override bool Overlaps(IEnumerable<T> other) => m_target.Overlaps(other);
  53. }
  54. }
  55. #pragma warning restore
  56. #endif