2 using System.Collections;
3 using System.Collections.Generic;
6 namespace ElmSharp.Wearable
8 class MoreOptionList : IList<MoreOptionItem>
10 MoreOption Owner { get; set; }
12 List<MoreOptionItem> Items { get; set; }
15 /// Sets or gets the count of Items
17 public int Count => Items.Count;
20 /// Sets or gets whether it is read only
22 public bool IsReadOnly => false;
25 /// Sets or gets the item with the index
27 /// <param name="index">the position of item in items</param>
28 /// <returns></returns>
29 public MoreOptionItem this[int index]
43 /// Creates and initializes a new instance of MoreOptionList class.
45 /// <param name="owner">the object of more option</param>
46 public MoreOptionList(MoreOption owner)
49 Items = new List<MoreOptionItem>();
53 /// Append a new item to a more option.
55 /// <param name="item">The more option item</param>
56 public void Add(MoreOptionItem item)
58 item.Handle = Interop.Eext.eext_more_option_item_append(Owner);
63 /// add a new item to a more option at the first.
65 /// <param name="item">The more option item</param>
66 public void AddFirst(MoreOptionItem item)
68 item.Handle = Interop.Eext.eext_more_option_item_prepend(Owner);
69 Items.Insert(0, item);
73 /// add a new item to a more option at the last.
75 /// <param name="item">The more option item</param>
76 public void AddLast(MoreOptionItem item)
82 /// Get the index of item
84 /// <param name="item">The more option item</param>
85 /// <returns>the index of item</returns>
86 public int IndexOf(MoreOptionItem item)
88 return Items.IndexOf(item);
92 /// Insert a new item into the more option after more option item with the index.
94 /// <param name="index">the index of item which is insert after</param>
95 /// <param name="item">The more option item</param>
96 public void Insert(int index, MoreOptionItem item)
98 if (Items.Count < index + 1 || index < 0)
99 throw new ArgumentOutOfRangeException("index is not valid in the MoreOption");
101 MoreOptionItem target = Items[index];
102 item.Handle = Interop.Eext.eext_more_option_item_insert_after(Owner, target.Handle);
103 Items.Insert(index, item);
107 /// Delete an item which is the given item index
109 /// <param name="index">the item index which will be deleted</param>
110 public void RemoveAt(int index)
112 if (Items.Count < index + 1 || index < 0)
113 throw new ArgumentOutOfRangeException("index is not valid in the MoreOptionList");
115 MoreOptionItem item = Items[index];
116 Interop.Eext.eext_more_option_item_del(item.Handle);
117 item.Handle = IntPtr.Zero;
118 Items.RemoveAt(index);
122 /// Remove all items from a given more option list object.
126 Interop.Eext.eext_more_option_items_clear(Owner);
127 foreach (MoreOptionItem item in Items)
129 item.Handle = IntPtr.Zero;
135 /// Check the item whether is contained
137 /// <param name="item">The more option item</param>
138 /// <returns>If contain return true, otherwise false</returns>
139 public bool Contains(MoreOptionItem item)
141 return Items.Contains(item);
147 /// <param name="array">the target array</param>
148 /// <param name="arrayIndex">which index the item will copy to</param>
149 public void CopyTo(MoreOptionItem[] array, int arrayIndex)
151 Items.CopyTo(array, arrayIndex);
157 /// <param name="item">the item will be removed</param>
158 /// <returns>if remove success return true, otherwise false</returns>
159 public bool Remove(MoreOptionItem item)
161 if (Items.Contains(item))
163 Interop.Eext.eext_more_option_item_del(item.Handle);
171 /// Return an enumerator that iterates through IEnumerator<MoreOptionItem>
173 /// <returns></returns>
174 public IEnumerator<MoreOptionItem> GetEnumerator()
176 return Items.GetEnumerator();
179 IEnumerator IEnumerable.GetEnumerator()
181 return Items.GetEnumerator();