You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace Net3_Proxy
  7. {
  8. public class IReadOnlyList<T> : IEnumerable<T>
  9. {
  10. private readonly IList<T> list;
  11. private IReadOnlyList(IList<T> lst)
  12. => list = lst;
  13. public IEnumerator<T> GetEnumerator() => list.GetEnumerator();
  14. IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)list).GetEnumerator();
  15. public int Count => list.Count;
  16. public T this[int index] => list[index];
  17. public static implicit operator IReadOnlyList<T>(List<T> list) => new IReadOnlyList<T>(list);
  18. }
  19. public class IReadOnlyDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
  20. {
  21. private readonly IDictionary<TKey, TValue> dict;
  22. private IReadOnlyDictionary(IDictionary<TKey, TValue> d)
  23. => dict = d;
  24. public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
  25. => dict.GetEnumerator();
  26. IEnumerator IEnumerable.GetEnumerator()
  27. => dict.GetEnumerator();
  28. public int Count => dict.Count;
  29. public bool ContainsKey(TKey key) => dict.ContainsKey(key);
  30. public bool TryGetValue(TKey key, out TValue val)
  31. => dict.TryGetValue(key, out val);
  32. public TValue this[TKey key] => dict[key];
  33. public static implicit operator IReadOnlyDictionary<TKey, TValue>(Dictionary<TKey, TValue> dict)
  34. => new IReadOnlyDictionary<TKey, TValue>(dict);
  35. }
  36. }