SimpleCollection<T> Class
Provides a generic collection with virtual methods to respond to and validate items being added or removed.
public class SimpleCollection<T> : Collection<T> where T : class
- Type Parameters:
-
T-The type of collection item.
- Inheritance:
- object Collection<T> object
- Derived:
- BarCommandCollection BarKeyboardShortcutCollection BarManagerDockableToolBarCollection BarModeCollection PopupMenuCollection
Constructors
SimpleCollection()
Initializes an instance of the class.
public SimpleCollection()
SimpleCollection(List<T>)
Initializes an instance of the class as a wrapper for the specified list.
public SimpleCollection(List<T> list)
| Parameter | Type | Description |
|---|---|---|
| list | List<T> |
Properties
DefaultComparer
Defines the default comparer to be used when sorting. If an explicit default is not defined, an implicit default will be used.
Methods
AddRange(IEnumerable<T>)
Adds the elements of the specified collection to the end of this collection.
public void AddRange(IEnumerable<T> collection)
| Parameter | Type | Description |
|---|---|---|
| collection | IEnumerable<T> | The collection whose elements should be added. |
ClearItems()
Removes all elements from the Collection<T>.
protected override sealed void ClearItems()
FindIndex(int, int, Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the List<T> that starts at the specified index and contains the specified number of elements.
public int FindIndex(int startIndex, int count, Predicate<T> match)
| Parameter | Type | Description |
|---|---|---|
| startIndex | int | The zero-based starting index of the search. |
| count | int | The number of elements in the section to search. |
| match | Predicate<T> | The Predicate<T> delegate that defines the conditions of the element to search for. |
Returns
- int:
The zero-based index of the first occurrence of an element that matches the conditions defined by
match, if found; otherwise, -1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
-or-
-or-
|
FindIndex(int, Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the List<T> that extends from the specified index to the last element.
public int FindIndex(int startIndex, Predicate<T> match)
| Parameter | Type | Description |
|---|---|---|
| startIndex | int | The zero-based starting index of the search. |
| match | Predicate<T> | The Predicate<T> delegate that defines the conditions of the element to search for. |
Returns
- int:
The zero-based index of the first occurrence of an element that matches the conditions defined by
match, if found; otherwise, -1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|
FindIndex(Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire List<T>.
public int FindIndex(Predicate<T> match)
| Parameter | Type | Description |
|---|---|---|
| match | Predicate<T> | The Predicate<T> delegate that defines the conditions of the element to search for. |
Returns
- int:
The zero-based index of the first occurrence of an element that matches the conditions defined by
match, if found; otherwise, -1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
FindLastIndex(int, int, Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the List<T> that contains the specified number of elements and ends at the specified index.
public int FindLastIndex(int startIndex, int count, Predicate<T> match)
| Parameter | Type | Description |
|---|---|---|
| startIndex | int | The zero-based starting index of the backward search. |
| count | int | The number of elements in the section to search. |
| match | Predicate<T> | The Predicate<T> delegate that defines the conditions of the element to search for. |
Returns
- int:
The zero-based index of the last occurrence of an element that matches the conditions defined by
match, if found; otherwise, -1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
-or-
-or-
|
FindLastIndex(int, Predicate<T>)
Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the List<T> that extends from the first element to the specified index.
public int FindLastIndex(int startIndex, Predicate<T> match)
| Parameter | Type | Description |
|---|---|---|
| startIndex | int | The zero-based starting index of the backward search. |
| match | Predicate<T> | The Predicate<T> delegate that defines the conditions of the element to search for. |
Returns
- int:
The zero-based index of the last occurrence of an element that matches the conditions defined by
match, if found; otherwise, -1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentOutOfRangeException |
|
ForEach(Action<T>)
Performs the specified action on each element of the List<T>.
public void ForEach(Action<T> action)
| Parameter | Type | Description |
|---|---|---|
| action | Action<T> | The Action<T> delegate to perform on each element of the List<T>. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| InvalidOperationException | An element in the collection has been modified. |
IndexOf(T, int)
Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the List<T> that extends from the specified index to the last element.
public int IndexOf(T item, int index)
| Parameter | Type | Description |
|---|---|---|
| item | T | The object to locate in the List<T>. The value can be |
| index | int | The zero-based starting index of the search. 0 (zero) is valid in an empty list. |
Returns
- int:
The zero-based index of the first occurrence of
itemwithin the range of elements in the List<T> that extends fromindexto the last element, if found; otherwise, -1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
IndexOf(T, int, int)
Searches for the specified object and returns the zero-based index of the first occurrence within the range of elements in the List<T> that starts at the specified index and contains the specified number of elements.
public int IndexOf(T item, int index, int count)
| Parameter | Type | Description |
|---|---|---|
| item | T | The object to locate in the List<T>. The value can be |
| index | int | The zero-based starting index of the search. 0 (zero) is valid in an empty list. |
| count | int | The number of elements in the section to search. |
Returns
- int:
The zero-based index of the first occurrence of
itemwithin the range of elements in the List<T> that starts atindexand containscountnumber of elements, if found; otherwise, -1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
-or-
-or-
|
InsertItem(int, T)
Inserts an element into the Collection<T> at the specified index.
protected override sealed void InsertItem(int index, T item)
| Parameter | Type | Description |
|---|---|---|
| index | int | The zero-based index at which |
| item | T | The object to insert. The value can be |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
-or-
|
InsertRange(int, IEnumerable<T>)
Inserts the elements of the specified collection into the collection starting at the specified index.
public void InsertRange(int index, IEnumerable<T> collection)
| Parameter | Type | Description |
|---|---|---|
| index | int | The zero-based index at which the new elements should be inserted. |
| collection | IEnumerable<T> | The collection whose elements should be added. |
LastIndexOf(T)
Searches for the specified object and returns the zero-based index of the last occurrence within the entire List<T>.
public int LastIndexOf(T item)
| Parameter | Type | Description |
|---|---|---|
| item | T | The object to locate in the List<T>. The value can be |
Returns
LastIndexOf(T, int)
Searches for the specified object and returns the zero-based index of the last occurrence within the range of elements in the List<T> that extends from the first element to the specified index.
public int LastIndexOf(T item, int index)
| Parameter | Type | Description |
|---|---|---|
| item | T | The object to locate in the List<T>. The value can be |
| index | int | The zero-based starting index of the backward search. |
Returns
- int:
The zero-based index of the last occurrence of
itemwithin the range of elements in the List<T> that extends from the first element toindex, if found; otherwise, -1.
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
|
OnItemAdded(int, T)
Performs additional custom processes after an item is added to the collection.
protected virtual void OnItemAdded(int index, T value)
| Parameter | Type | Description |
|---|---|---|
| index | int | The zero-based index at which the item was inserted. |
| value | T | The object that was inserted. |
Remarks
The default implementation of this method is intended to be overridden by a derived class to perform some action after the specified object is added.
OnItemAdding(int, T)
Performs additional custom processes before an item is added to the collection.
protected virtual void OnItemAdding(int index, T value)
| Parameter | Type | Description |
|---|---|---|
| index | int | The zero-based index at which the item was inserted. |
| value | T | The object that was inserted. |
Remarks
The default implementation of this method is intended to be overridden by a derived class to perform some action after the specified object is added.
OnItemRemoved(int, T)
Performs additional custom processes after an item is removed from the collection.
protected virtual void OnItemRemoved(int index, T value)
| Parameter | Type | Description |
|---|---|---|
| index | int | The zero-based index from which the item was removed. |
| value | T | The object that was removed. |
Remarks
The default implementation of this method is intended to be overridden by a derived class to perform some action after the specified object is removed.
OnItemRemoving(int, T)
Performs additional custom processes before an item is removed from the collection.
protected virtual void OnItemRemoving(int index, T value)
| Parameter | Type | Description |
|---|---|---|
| index | int | The zero-based index from which the item was removed. |
| value | T | The object that was removed. |
Remarks
The default implementation of this method is intended to be overridden by a derived class to perform some action before the specified object is removed.
OnValidate(T, int)
Performs additional custom processes when validating a value.
protected virtual void OnValidate(T value, int existingIndex)
| Parameter | Type | Description |
|---|---|---|
| value | T | The object to validate. |
| existingIndex | int | The index within the collection of the object that would be replaced by the value. |
Remarks
The default implementation of this method determines whether value is null, and if so,
throws ArgumentNullException. It is intended to be overridden by a derived class to
perform additional action when the specified element is validated.
RemoveItem(int)
Removes the element at the specified index of the Collection<T>.
protected override void RemoveItem(int index)
| Parameter | Type | Description |
|---|---|---|
| index | int | The zero-based index of the element to remove. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
-or-
|
SetItem(int, T)
Replaces the element at the specified index.
protected override void SetItem(int index, T item)
| Parameter | Type | Description |
|---|---|---|
| index | int | The zero-based index of the element to replace. |
| item | T | The new value for the element at the specified index. The value can be |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException |
-or-
|
Sort()
Sorts the elements in the entire List<T> using the default comparer.
public void Sort()
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | The default comparer Default cannot find an implementation of the IComparable<T> generic interface or the IComparable interface for type |
Sort(IComparer<T>)
Sorts the elements in the entire List<T> using the specified comparer.
public void Sort(IComparer<T> comparer)
| Parameter | Type | Description |
|---|---|---|
| comparer | IComparer<T> | The IComparer<T> implementation to use when comparing elements, or |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException |
|
| ArgumentException | The implementation of |
Sort(Comparison<T>)
Sorts the elements in the entire List<T> using the specified Comparison<T>.
public void Sort(Comparison<T> comparison)
| Parameter | Type | Description |
|---|---|---|
| comparison | Comparison<T> | The Comparison<T> to use when comparing elements. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException | The implementation of |
Inherited Members
- object.GetType()
- object.MemberwiseClone()
- object.ToString()
- object.Equals(object)
- object.Equals(object, object)
- object.ReferenceEquals(object, object)
- object.GetHashCode()