MultiEditorItemSet.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. namespace TSZ.DotNetDll.WinForms
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Reflection;
  7. public class MultiEditorItemSet : IEnumerable<MultiEditorItem>, IEnumerable
  8. {
  9. private List<MultiEditorItem> _Items = new List<MultiEditorItem>();
  10. public MultiEditorItem Add(MultiEditorItem item)
  11. {
  12. this._Items.Add(item);
  13. return item;
  14. }
  15. public IEnumerable<MultiEditorItem> AddRang(IEnumerable<MultiEditorItem> items)
  16. {
  17. this._Items.AddRange(items);
  18. return items;
  19. }
  20. public T AddT<T>(T item) where T: MultiEditorItem
  21. {
  22. this._Items.Add(item);
  23. return item;
  24. }
  25. public MultiEditorItem[] Clear()
  26. {
  27. MultiEditorItem[] itemArray = this._Items.ToArray();
  28. this._Items.Clear();
  29. return itemArray;
  30. }
  31. public IEnumerator<MultiEditorItem> GetEnumerator()
  32. {
  33. return this._Items.GetEnumerator();
  34. }
  35. public MultiEditorItem IndexOf(string itemLable)
  36. {
  37. for (int i = 0; i < this._Items.Count; i++)
  38. {
  39. if (this._Items[i].Label == itemLable)
  40. {
  41. return this._Items[i];
  42. }
  43. }
  44. return null;
  45. }
  46. public int IndexOf(MultiEditorItem item)
  47. {
  48. return this._Items.IndexOf(item);
  49. }
  50. public MultiEditorItem Insert(int index, MultiEditorItem item)
  51. {
  52. this._Items.Insert(index, item);
  53. return item;
  54. }
  55. public bool Remove(string itemLable)
  56. {
  57. MultiEditorItem index = this.IndexOf(itemLable);
  58. if (index != null)
  59. {
  60. this.Remove(index);
  61. return true;
  62. }
  63. return false;
  64. }
  65. public bool Remove(MultiEditorItem item)
  66. {
  67. return this._Items.Remove(item);
  68. }
  69. public MultiEditorItem RemoveAt(int index)
  70. {
  71. if ((index >= 0) && (index < this._Items.Count))
  72. {
  73. MultiEditorItem item = this._Items[index];
  74. this._Items.RemoveAt(index);
  75. return item;
  76. }
  77. return null;
  78. }
  79. IEnumerator IEnumerable.GetEnumerator()
  80. {
  81. return this._Items.GetEnumerator();
  82. }
  83. public MultiEditorItem[] ToArray()
  84. {
  85. return this._Items.ToArray();
  86. }
  87. public int Count
  88. {
  89. get
  90. {
  91. return this._Items.Count;
  92. }
  93. }
  94. public MultiEditorItem this[int index]
  95. {
  96. get
  97. {
  98. return this._Items[index];
  99. }
  100. }
  101. public MultiEditorItem[] Items
  102. {
  103. get
  104. {
  105. return this._Items.ToArray();
  106. }
  107. }
  108. }
  109. }