using System; using System.Collections; using System.Collections.Generic; using System.Text; namespace ElmSharp.Wearable { class MoreOptionList : IList { MoreOption Owner { get; set; } List Items { get; set; } /// /// Sets or gets the count of Items /// public int Count => Items.Count; /// /// Sets or gets whether it is read only /// public bool IsReadOnly => false; /// /// Sets or gets the item with the index /// /// the position of item in items /// public MoreOptionItem this[int index] { get { return Items[index]; } set { Items[index] = value; } } /// /// Creates and initializes a new instance of MoreOptionList class. /// /// the object of more option public MoreOptionList(MoreOption owner) { Owner = owner; Items = new List(); } /// /// Append a new item to a more option. /// /// The more option item public void Add(MoreOptionItem item) { item.Handle = Interop.Eext.eext_more_option_item_append(Owner); Items.Add(item); } /// /// add a new item to a more option at the first. /// /// The more option item public void AddFirst(MoreOptionItem item) { item.Handle = Interop.Eext.eext_more_option_item_prepend(Owner); Items.Insert(0, item); } /// /// add a new item to a more option at the last. /// /// The more option item public void AddLast(MoreOptionItem item) { Add(item); } /// /// Get the index of item /// /// The more option item /// the index of item public int IndexOf(MoreOptionItem item) { return Items.IndexOf(item); } /// /// Insert a new item into the more option after more option item with the index. /// /// the index of item which is insert after /// The more option item public void Insert(int index, MoreOptionItem item) { if (Items.Count < index + 1 || index < 0) throw new ArgumentOutOfRangeException("index is not valid in the MoreOption"); MoreOptionItem target = Items[index]; item.Handle = Interop.Eext.eext_more_option_item_insert_after(Owner, target.Handle); Items.Insert(index, item); } /// /// Delete an item which is the given item index /// /// the item index which will be deleted public void RemoveAt(int index) { if (Items.Count < index + 1 || index < 0) throw new ArgumentOutOfRangeException("index is not valid in the MoreOptionList"); MoreOptionItem item = Items[index]; Interop.Eext.eext_more_option_item_del(item.Handle); item.Handle = IntPtr.Zero; Items.RemoveAt(index); } /// /// Remove all items from a given more option list object. /// public void Clear() { Interop.Eext.eext_more_option_items_clear(Owner); foreach (MoreOptionItem item in Items) { item.Handle = IntPtr.Zero; } Items.Clear(); } /// /// Check the item whether is contained /// /// The more option item /// If contain return true, otherwise false public bool Contains(MoreOptionItem item) { return Items.Contains(item); } /// /// Copy Items /// /// the target array /// which index the item will copy to public void CopyTo(MoreOptionItem[] array, int arrayIndex) { Items.CopyTo(array, arrayIndex); } /// /// Remove a item /// /// the item will be removed /// if remove success return true, otherwise false public bool Remove(MoreOptionItem item) { if (Items.Contains(item)) { Interop.Eext.eext_more_option_item_del(item.Handle); Items.Remove(item); return true; } return false; } /// /// Return an enumerator that iterates through IEnumerator /// /// public IEnumerator GetEnumerator() { return Items.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return Items.GetEnumerator(); } } }