Table of Contents

Class BindableList<T>

Namespace
Bindables
Assembly
Bindables.dll

A bindable list implementation that raises events when the list or its elements are modified. Supports change notifications at both the list level and individual element level.

[Serializable]
public class BindableList<T> : Bindable<List<T>>, IBindWritable<List<T>>, IBindWritable, IBindableList<T>, IBindable<List<T>>, IBindable, IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable

Type Parameters

T

The type of elements in the list.

Inheritance
BindableList<T>
Implements
Inherited Members
Extension Methods

Constructors

BindableList()

Initializes a new instance of the BindableList<T> class that is empty.

public BindableList()

BindableList(IEnumerable<T>)

Initializes a new instance of the BindableList<T> class that contains elements copied from the specified collection.

public BindableList(IEnumerable<T> collection)

Parameters

collection IEnumerable<T>

The collection whose elements are copied to the new list.

BindableList(int)

Initializes a new instance of the BindableList<T> class that is empty and has the specified initial capacity.

public BindableList(int capacity)

Parameters

capacity int

The initial number of elements that the list can contain.

Properties

BindableCount

Gets a bindable property for the count of elements in the list. This allows observing changes to the list count.

public IBindable<int> BindableCount { get; }

Property Value

IBindable<int>

Capacity

Gets or sets the total number of elements the internal data structure can hold without resizing.

public int Capacity { get; set; }

Property Value

int

Count

public int Count { get; }

Property Value

int

IsFixedSize

public bool IsFixedSize { get; }

Property Value

bool

IsReadOnly

public bool IsReadOnly { get; }

Property Value

bool

IsSynchronized

public bool IsSynchronized { get; }

Property Value

bool

this[int]

Gets or sets the element at the specified index. Setting a different value raises the OnElementChange event.

public T this[int index] { get; set; }

Parameters

index int

The zero-based index of the element to get or set.

Property Value

T

The element at the specified index.

SyncRoot

public object SyncRoot { get; }

Property Value

object

Value

Gets or sets the underlying list value. Setting this property replaces the entire list and raises the Changed event.

public List<T> Value { get; set; }

Property Value

List<T>

Methods

Add(object)

Adds an element to the end of the list using non-generic object type.

public int Add(object value)

Parameters

value object

The object to add to the list.

Returns

int

The position into which the new element was inserted.

Add(T)

Adds an element to the end of the list and raises the OnElementAdd event.

public void Add(T item)

Parameters

item T

The element to add to the list.

AddRange(IEnumerable<T>)

Adds the elements of the specified collection to the end of the list. Raises the OnElementAdd event for each element.

public void AddRange(IEnumerable<T> collection)

Parameters

collection IEnumerable<T>

The collection whose elements should be added to the list.

BinarySearch(int, int, T, IComparer<T>)

Searches a range of elements in the sorted list for an element using the specified comparer and returns the zero-based index of the element.

public int BinarySearch(int index, int count, T item, IComparer<T> comparer)

Parameters

index int

The zero-based starting index of the range to search.

count int

The length of the range to search.

item T

The element to locate.

comparer IComparer<T>

The comparer to use when comparing elements.

Returns

int

The zero-based index of the element in the sorted list, if found; otherwise, a negative number.

BinarySearch(T)

Searches the entire sorted list for an element using the default comparer and returns the zero-based index of the element.

public int BinarySearch(T item)

Parameters

item T

The element to locate.

Returns

int

The zero-based index of the element in the sorted list, if found; otherwise, a negative number.

BinarySearch(T, IComparer<T>)

Searches the entire sorted list for an element using the specified comparer and returns the zero-based index of the element.

public int BinarySearch(T item, IComparer<T> comparer)

Parameters

item T

The element to locate.

comparer IComparer<T>

The comparer to use when comparing elements.

Returns

int

The zero-based index of the element in the sorted list, if found; otherwise, a negative number.

Clear()

Removes all elements from the list and raises the Changed event if the list was not empty.

public void Clear()

Contains(object)

Determines whether the list contains a specific value using non-generic object type.

public bool Contains(object value)

Parameters

value object

The object to locate in the list.

Returns

bool

true if the object is found in the list; otherwise, false.

Contains(T)

public bool Contains(T item)

Parameters

item T

Returns

bool

CopyTo(Array, int)

public void CopyTo(Array array, int index)

Parameters

array Array
index int

CopyTo(int, T[], int, int)

Copies a range of elements from the list to a compatible one-dimensional array, starting at the specified index of the target array.

public void CopyTo(int index, T[] array, int arrayIndex, int count)

Parameters

index int

The zero-based index in the source list at which copying begins.

array T[]

The one-dimensional array that is the destination of the elements copied from the list.

arrayIndex int

The zero-based index in array at which copying begins.

count int

The number of elements to copy.

CopyTo(T[])

Copies the entire list to a compatible one-dimensional array, starting at the beginning of the target array.

public void CopyTo(T[] array)

Parameters

array T[]

The one-dimensional array that is the destination of the elements copied from the list.

CopyTo(T[], int)

public void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]
arrayIndex int

DeriveCast<TResult>()

Creates a derived bindable list that casts each element to the specified type. The derived list automatically updates when elements are added, changed, or removed from the source list.

public BindableList<TResult> DeriveCast<TResult>()

Returns

BindableList<TResult>

A bindable list containing the cast elements.

Type Parameters

TResult

The type to cast elements to.

DeriveConcat(BindableList<T>)

Creates a derived bindable list that concatenates this list with another list. The derived list automatically updates when elements are added, changed, or removed from either source list.

public BindableList<T> DeriveConcat(BindableList<T> second)

Parameters

second BindableList<T>

The second list to concatenate.

Returns

BindableList<T>

A bindable list containing the concatenated elements.

DeriveSelect<TResult>(Func<T, int, TResult>)

Creates a derived bindable list that projects each element using the specified selector function that incorporates the element's index. The derived list automatically updates when elements are added, changed, or removed from the source list.

public BindableList<TResult> DeriveSelect<TResult>(Func<T, int, TResult> selector)

Parameters

selector Func<T, int, TResult>

A transform function to apply to each source element; the second parameter of the function represents the index of the source element.

Returns

BindableList<TResult>

A bindable list whose elements are the result of invoking the transform function on each element.

Type Parameters

TResult

The type of the value returned by the selector.

DeriveSelect<TResult>(Func<T, TResult>)

Creates a derived bindable list that projects each element using the specified selector function. The derived list automatically updates when elements are added, changed, or removed from the source list.

public BindableList<TResult> DeriveSelect<TResult>(Func<T, TResult> selector)

Parameters

selector Func<T, TResult>

A transform function to apply to each element.

Returns

BindableList<TResult>

A bindable list whose elements are the result of invoking the transform function on each element.

Type Parameters

TResult

The type of the value returned by the selector.

DeriveToDictionary<TKey>(Func<T, TKey>)

Creates a derived bindable dictionary from the list according to a specified key selector function. The derived dictionary automatically updates when elements are added, changed, or removed from the source list.

public BindableDictionary<TKey, T> DeriveToDictionary<TKey>(Func<T, TKey> keySelector)

Parameters

keySelector Func<T, TKey>

A function to extract a key from each element.

Returns

BindableDictionary<TKey, T>

A bindable dictionary that contains keys and values.

Type Parameters

TKey

The type of the key returned by keySelector.

DeriveToDictionary<TKey>(Func<T, TKey>, IEqualityComparer<TKey>)

Creates a derived bindable dictionary from the list according to a specified key selector function and key comparer. The derived dictionary automatically updates when elements are added, changed, or removed from the source list.

public BindableDictionary<TKey, T> DeriveToDictionary<TKey>(Func<T, TKey> keySelector, IEqualityComparer<TKey> comparer)

Parameters

keySelector Func<T, TKey>

A function to extract a key from each element.

comparer IEqualityComparer<TKey>

An equality comparer to compare keys.

Returns

BindableDictionary<TKey, T>

A bindable dictionary that contains keys and values.

Type Parameters

TKey

The type of the key returned by keySelector.

DeriveToDictionary<TKey, TValue>(Func<T, TKey>, Func<T, TValue>, IEqualityComparer<TKey>)

Creates a derived bindable dictionary from the list according to specified key selector and element selector functions, and a key comparer. The derived dictionary automatically updates when elements are added, changed, or removed from the source list.

public BindableDictionary<TKey, TValue> DeriveToDictionary<TKey, TValue>(Func<T, TKey> keySelector, Func<T, TValue> elementSelector, IEqualityComparer<TKey> comparer)

Parameters

keySelector Func<T, TKey>

A function to extract a key from each element.

elementSelector Func<T, TValue>

A transform function to produce a result element value from each element.

comparer IEqualityComparer<TKey>

An equality comparer to compare keys.

Returns

BindableDictionary<TKey, TValue>

A bindable dictionary that contains values of type TValue selected from the input sequence.

Type Parameters

TKey

The type of the key returned by keySelector.

TValue

The type of the value returned by elementSelector.

Exists(Predicate<T>)

Determines whether the list contains an element that matches the conditions defined by the specified predicate.

public bool Exists(Predicate<T> match)

Parameters

match Predicate<T>

The predicate that defines the conditions of the element to search for.

Returns

bool

true if the list contains one or more elements that match the conditions defined by the predicate; otherwise, false.

Find(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire list.

public T Find(Predicate<T> match)

Parameters

match Predicate<T>

The predicate that defines the conditions of the element to search for.

Returns

T

The first element that matches the conditions if found; otherwise, the default value for type T.

FindAll(Predicate<T>)

Retrieves all the elements that match the conditions defined by the specified predicate.

public List<T> FindAll(Predicate<T> match)

Parameters

match Predicate<T>

The predicate that defines the conditions of the elements to search for.

Returns

List<T>

A list containing all the elements that match the conditions if found; otherwise, an empty list.

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 that starts at the specified index and contains the specified number of elements.

public int FindIndex(int startIndex, int count, Predicate<T> match)

Parameters

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 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 if found; otherwise, -1.

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 that extends from the specified index to the last element.

public int FindIndex(int startIndex, Predicate<T> match)

Parameters

startIndex int

The zero-based starting index of the search.

match Predicate<T>

The predicate 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 if found; otherwise, -1.

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.

public int FindIndex(Predicate<T> match)

Parameters

match Predicate<T>

The predicate 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 if found; otherwise, -1.

FindLast(Predicate<T>)

Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire list.

public T FindLast(Predicate<T> match)

Parameters

match Predicate<T>

The predicate that defines the conditions of the element to search for.

Returns

T

The last element that matches the conditions if found; otherwise, the default value for type T.

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 that contains the specified number of elements and ends at the specified index.

public int FindLastIndex(int startIndex, int count, Predicate<T> match)

Parameters

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 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 if found; otherwise, -1.

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 that extends from the first element to the specified index.

public int FindLastIndex(int startIndex, Predicate<T> match)

Parameters

startIndex int

The zero-based starting index of the backward search.

match Predicate<T>

The predicate 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 if found; otherwise, -1.

FindLastIndex(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 entire list.

public int FindLastIndex(Predicate<T> match)

Parameters

match Predicate<T>

The predicate 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 if found; otherwise, -1.

ForEach(Action<T>)

Performs the specified action on each element of the list.

public void ForEach(Action<T> action)

Parameters

action Action<T>

The action to perform on each element of the list.

GetEnumerator()

public IEnumerator<T> GetEnumerator()

Returns

IEnumerator<T>

GetRange(int, int)

Creates a shallow copy of a range of elements in the source list.

public List<T> GetRange(int index, int count)

Parameters

index int

The zero-based index at which the range starts.

count int

The number of elements in the range.

Returns

List<T>

A shallow copy of a range of elements in the source list.

IndexOf(object)

Determines the index of a specific item in the list using non-generic object type.

public int IndexOf(object value)

Parameters

value object

The object to locate in the list.

Returns

int

The index of value if found in the list; otherwise, -1.

IndexOf(T)

public int IndexOf(T item)

Parameters

item T

Returns

int

IndexOf(T, int)

Searches for the specified element and returns the zero-based index of the first occurrence within the range of elements that starts at the specified index.

public int IndexOf(T item, int index)

Parameters

item T

The element to locate in the list.

index int

The zero-based starting index of the search.

Returns

int

The zero-based index of the first occurrence of item, if found; otherwise, -1.

IndexOf(T, int, int)

Searches for the specified element and returns the zero-based index of the first occurrence within the range of elements that starts at the specified index and contains the specified number of elements.

public int IndexOf(T item, int index, int count)

Parameters

item T

The element to locate in the list.

index int

The zero-based starting index of the search.

count int

The number of elements in the section to search.

Returns

int

The zero-based index of the first occurrence of item, if found; otherwise, -1.

Insert(int, object)

Inserts an element into the list at the specified index using non-generic object type.

public void Insert(int index, object value)

Parameters

index int

The zero-based index at which value should be inserted.

value object

The object to insert into the list.

Insert(int, T)

Inserts an element into the list at the specified index and raises the OnElementAdd event.

public void Insert(int index, T item)

Parameters

index int

The zero-based index at which item should be inserted.

item T

The element to insert.

InsertRange(int, IEnumerable<T>)

Inserts the elements of a collection into the list at the specified index. Raises the OnElementAdd event for each element.

public void InsertRange(int index, IEnumerable<T> collection)

Parameters

index int

The zero-based index at which the new elements should be inserted.

collection IEnumerable<T>

The collection whose elements should be inserted into the list.

LastIndexOf(T)

Searches for the specified element and returns the zero-based index of the last occurrence within the entire list.

public int LastIndexOf(T item)

Parameters

item T

The element to locate in the list.

Returns

int

The zero-based index of the last occurrence of item, if found; otherwise, -1.

LastIndexOf(T, int)

Searches for the specified element and returns the zero-based index of the last occurrence within the range of elements that extends from the first element to the specified index.

public int LastIndexOf(T item, int index)

Parameters

item T

The element to locate in the list.

index int

The zero-based starting index of the backward search.

Returns

int

The zero-based index of the last occurrence of item, if found; otherwise, -1.

LastIndexOf(T, int, int)

Searches for the specified element and returns the zero-based index of the last occurrence within the range of elements that contains the specified number of elements and ends at the specified index.

public int LastIndexOf(T item, int index, int count)

Parameters

item T

The element to locate in the list.

index int

The zero-based starting index of the backward search.

count int

The number of elements in the section to search.

Returns

int

The zero-based index of the last occurrence of item, if found; otherwise, -1.

Move(int, int)

Moves an element from one index to another and raises the OnElementMove event.

public void Move(int fromIndex, int toIndex)

Parameters

fromIndex int

The zero-based index of the element to move.

toIndex int

The zero-based index to move the element to.

Remove(object)

Removes the first occurrence of a specific object from the list using non-generic object type.

public void Remove(object value)

Parameters

value object

The object to remove from the list.

Remove(T)

Removes the first occurrence of a specific element from the list and raises the OnElementRemove event.

public bool Remove(T item)

Parameters

item T

The element to remove from the list.

Returns

bool

true if the element was successfully removed; otherwise, false.

RemoveAll(Predicate<T>)

Removes all elements that match the conditions defined by the specified predicate. Raises the OnElementRemove event for each removed element.

public int RemoveAll(Predicate<T> match)

Parameters

match Predicate<T>

The predicate that defines the conditions of the elements to remove.

Returns

int

The number of elements removed from the list.

RemoveAt(int)

Removes the element at the specified index and raises the OnElementRemove event.

public void RemoveAt(int index)

Parameters

index int

The zero-based index of the element to remove.

RemoveRange(int, int)

Removes a range of elements from the list. Raises the OnElementRemove event for each removed element.

public void RemoveRange(int index, int count)

Parameters

index int

The zero-based starting index of the range of elements to remove.

count int

The number of elements to remove.

Reverse()

Reverses the order of all elements in the list and raises the Changed event if the list was not empty.

public void Reverse()

Reverse(int, int)

Reverses the order of elements in the specified range and raises the Changed event if the list was not empty.

public void Reverse(int index, int count)

Parameters

index int

The zero-based starting index of the range to reverse.

count int

The number of elements in the range to reverse.

Sort()

Sorts the elements in the entire list using the default comparer and raises the Changed event if the list was not empty.

public void Sort()

Sort(IComparer<T>)

Sorts the elements in the entire list using the specified comparer and raises the Changed event if the list was not empty.

public void Sort(IComparer<T> comparer)

Parameters

comparer IComparer<T>

The comparer to use when comparing elements.

Sort(Comparison<T>)

Sorts the elements in the entire list using the specified comparison and raises the Changed event if the list was not empty.

public void Sort(Comparison<T> comparison)

Parameters

comparison Comparison<T>

The comparison to use when comparing elements.

Sort(int, int, IComparer<T>)

Sorts the elements in a range of elements in the list using the specified comparer and raises the Changed event if the list was not empty.

public void Sort(int index, int count, IComparer<T> comparer)

Parameters

index int

The zero-based starting index of the range to sort.

count int

The length of the range to sort.

comparer IComparer<T>

The comparer to use when comparing elements.

Swap(int, int)

Swaps two elements in the list and raises the OnElementSwap event.

public void Swap(int index1, int index2)

Parameters

index1 int

The zero-based index of the first element.

index2 int

The zero-based index of the second element.

TrueForAll(Predicate<T>)

Determines whether every element in the list matches the conditions defined by the specified predicate.

public bool TrueForAll(Predicate<T> match)

Parameters

match Predicate<T>

The predicate that defines the conditions to check against the elements.

Returns

bool

true if every element in the list matches the conditions; otherwise, false.

Events

OnElementAdd

Occurs when an element is added to the list.

public event Action<int, T> OnElementAdd

Event Type

Action<int, T>

OnElementChange

Occurs when an element's value is changed in the list.

public event Action<int, T, T> OnElementChange

Event Type

Action<int, T, T>

OnElementMove

Occurs when an element is moved within the list.

public event Action<int, int> OnElementMove

Event Type

Action<int, int>

OnElementRemove

Occurs when an element is removed from the list.

public event Action<int, T> OnElementRemove

Event Type

Action<int, T>

OnElementSwap

Occurs when two elements are swapped in the list.

public event Action<int, int> OnElementSwap

Event Type

Action<int, int>