/// <summary> /// Inserts a new item at the given index to the list. /// </summary> /// <param name="index">The index to place the new item.</param> /// <param name="item">The item to add.</param> public void Insert(int index, ObjectField item) { IList list = Value as IList; if (list != null) { list.Insert(index, item.Value); Items.Insert(index, item); Count++; RefreshItemNames(); OnItemAdded(item); } }
/// <summary> /// Removes an item from the list. /// </summary> /// <param name="item">The item to remove.</param> public override void Remove(ObjectField item) { IList list = Value as IList; if (list != null && Items.Contains(item)) { list.Remove(item.Value); Items.Remove(item); RefreshItemNames(); Count--; OnItemRemoved(item); } }
/// <summary> /// Adds a new item to the list. /// </summary> /// <param name="item">The item to add.</param> public override void Add(ObjectField item) { IList list = Value as IList; if (list != null) { list.Add(item.Value); Items.Add(item); Count++; RefreshItemNames(); OnItemAdded(item); } }
/// <summary> /// Removes an item from the dictionary. /// </summary> /// <param name="item">The item to remove.</param> public override void Remove(ObjectField item) { IDictionary dictionary = Value as IDictionary; string key = item.NameTag as string; if (dictionary != null && key != null) { dictionary.Remove(key); Items.Remove(key); Count--; OnItemRemoved(item); } }
/// <summary> /// Adds a new item to the dictionary. /// </summary> /// <param name="item">The item itself.</param> public override void Add(ObjectField item) { IDictionary dictionary = Value as IDictionary; string key = item.NameTag as string; if (dictionary != null && key != null) { dictionary.Add(key, item.Value); Items.Add(key, item); Count++; OnItemAdded(item); } }
/// <summary> /// Moves an item of the list to another position. /// </summary> /// <param name="item">The item to move.</param> /// <param name="newIndex">The new position inside the list of items.</param> public void Move(ObjectField item, int newIndex) { int oldIndex = Items.IndexOf(item); IList list = Value as IList; if (list != null && oldIndex >= 0) { Remove(item); if (oldIndex < newIndex) { list.Insert(newIndex - 1, item.Value); Items.Insert(newIndex - 1, item); } else { list.Insert(newIndex, item.Value); Items.Insert(newIndex, item); } Count++; // We removed the old item, so Count was decreased before. RefreshItemNames(); OnItemAdded(item); } }
/// <summary> /// Removes an item from the collection. /// </summary> /// <param name="item">The item to remove.</param> public abstract void Remove(ObjectField item);
// ======================================================================== // Methods #region === Methods /// <summary> /// Adds a new item to the collection. /// </summary> /// <param name="item">The item itself.</param> public abstract void Add(ObjectField item);