ReadOnlySortedDictionary.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. namespace wf
  4. {
  5. public class ReadOnlySortedDictionary<Tkey, TVal>
  6. {
  7. public ReadOnlySortedDictionary(SortedDictionary<Tkey, TVal> srcData)
  8. {
  9. this.srcData = srcData;
  10. }
  11. public TVal this[Tkey key]
  12. {
  13. get
  14. {
  15. return this.Get(key);
  16. }
  17. }
  18. public int Count
  19. {
  20. get
  21. {
  22. return this.srcData.Count;
  23. }
  24. }
  25. public bool ContainsKey(Tkey key)
  26. {
  27. return this.srcData.ContainsKey(key);
  28. }
  29. public TVal Get(Tkey key)
  30. {
  31. return this.srcData[key];
  32. }
  33. public Tkey[] GetKeyArray()
  34. {
  35. Tkey[] array = new Tkey[this.srcData.Count];
  36. int num = 0;
  37. foreach (KeyValuePair<Tkey, TVal> keyValuePair in this.srcData)
  38. {
  39. array[num++] = keyValuePair.Key;
  40. }
  41. return array;
  42. }
  43. public TVal[] GetValueArray()
  44. {
  45. TVal[] array = new TVal[this.srcData.Count];
  46. int num = 0;
  47. foreach (KeyValuePair<Tkey, TVal> keyValuePair in this.srcData)
  48. {
  49. array[num++] = keyValuePair.Value;
  50. }
  51. return array;
  52. }
  53. public SortedDictionary<Tkey, TVal> Copy()
  54. {
  55. return new SortedDictionary<Tkey, TVal>(this.srcData);
  56. }
  57. private SortedDictionary<Tkey, TVal> srcData;
  58. }
  59. }