ReadOnlyCollection.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. namespace SharpCompress
  5. {
  6. internal class ReadOnlyCollection<T> : ICollection<T>
  7. {
  8. private readonly ICollection<T> collection;
  9. public ReadOnlyCollection(ICollection<T> collection)
  10. {
  11. this.collection = collection;
  12. }
  13. public void Add(T item)
  14. {
  15. throw new NotSupportedException();
  16. }
  17. public void Clear()
  18. {
  19. throw new NotSupportedException();
  20. }
  21. public bool Contains(T item)
  22. {
  23. return collection.Contains(item);
  24. }
  25. public void CopyTo(T[] array, int arrayIndex)
  26. {
  27. collection.CopyTo(array, arrayIndex);
  28. }
  29. public int Count => collection.Count;
  30. public bool IsReadOnly => true;
  31. public bool Remove(T item)
  32. {
  33. throw new NotSupportedException();
  34. }
  35. public IEnumerator<T> GetEnumerator()
  36. {
  37. return collection.GetEnumerator();
  38. }
  39. IEnumerator IEnumerable.GetEnumerator()
  40. {
  41. throw new NotSupportedException();
  42. }
  43. }
  44. }