ReadOnlyList.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 ReadOnlyList<T>
  8. : IList<T>
  9. {
  10. public T this[int index]
  11. {
  12. get { return Lookup(index); }
  13. set { throw new NotSupportedException(); }
  14. }
  15. System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
  16. {
  17. return GetEnumerator();
  18. }
  19. public bool IsReadOnly => true;
  20. public void Add(T item) => throw new NotSupportedException();
  21. public void Clear() => throw new NotSupportedException();
  22. public void Insert(int index, T item) => throw new NotSupportedException();
  23. public bool Remove(T item) => throw new NotSupportedException();
  24. public void RemoveAt(int index) => throw new NotSupportedException();
  25. public abstract bool Contains(T item);
  26. public abstract void CopyTo(T[] array, int arrayIndex);
  27. public abstract int Count { get; }
  28. public abstract IEnumerator<T> GetEnumerator();
  29. public abstract int IndexOf(T item);
  30. protected abstract T Lookup(int index);
  31. }
  32. internal class ReadOnlyListProxy<T>
  33. : ReadOnlyList<T>
  34. {
  35. private readonly IList<T> m_target;
  36. internal ReadOnlyListProxy(IList<T> target)
  37. {
  38. if (target == null)
  39. throw new ArgumentNullException(nameof(target));
  40. m_target = target;
  41. }
  42. public override int Count => m_target.Count;
  43. public override bool Contains(T item) => m_target.Contains(item);
  44. public override void CopyTo(T[] array, int arrayIndex) => m_target.CopyTo(array, arrayIndex);
  45. public override IEnumerator<T> GetEnumerator() => m_target.GetEnumerator();
  46. public override int IndexOf(T item) => m_target.IndexOf(item);
  47. protected override T Lookup(int index) => m_target[index];
  48. }
  49. }
  50. #pragma warning restore
  51. #endif