ReadOnlyCollection.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 ReadOnlyCollection<T>
  8. : ICollection<T>
  9. {
  10. System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
  11. {
  12. return GetEnumerator();
  13. }
  14. public bool IsReadOnly => true;
  15. public void Add(T item) => throw new NotSupportedException();
  16. public void Clear() => throw new NotSupportedException();
  17. public bool Remove(T item) => throw new NotSupportedException();
  18. public abstract bool Contains(T item);
  19. public abstract int Count { get; }
  20. public abstract void CopyTo(T[] array, int arrayIndex);
  21. public abstract IEnumerator<T> GetEnumerator();
  22. }
  23. internal class ReadOnlyCollectionProxy<T>
  24. : ReadOnlyCollection<T>
  25. {
  26. private readonly ICollection<T> m_target;
  27. internal ReadOnlyCollectionProxy(ICollection<T> target)
  28. {
  29. if (target == null)
  30. throw new ArgumentNullException(nameof(target));
  31. m_target = target;
  32. }
  33. public override bool Contains(T item) => m_target.Contains(item);
  34. public override int Count => m_target.Count;
  35. public override void CopyTo(T[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex);
  36. public override IEnumerator<T> GetEnumerator() => m_target.GetEnumerator();
  37. }
  38. }
  39. #pragma warning restore
  40. #endif