Class ChangeAwareList<T>
- Namespace
- DynamicData
- Assembly
- DynamicData.dll
A list which captures all changes which are made to it. These changes are recorded until CaptureChanges() at which point the changes are cleared.
Used for creating custom operators.
public class ChangeAwareList<T> : IExtendedList<T>, IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable where T : notnull
Type Parameters
T
The item type.
- Inheritance
-
ChangeAwareList<T>
- Implements
-
IList<T>ICollection<T>IEnumerable<T>
- Extension Methods
Constructors
ChangeAwareList(ChangeAwareList<T>, bool)
Initializes a new instance of the ChangeAwareList<T> class. Clone an existing ChangeAwareList.
public ChangeAwareList(ChangeAwareList<T> list, bool copyChanges)
Parameters
list
ChangeAwareList<T>The original ChangeAwareList to copy.
copyChanges
boolShould the list of changes also be copied over?.
ChangeAwareList(IEnumerable<T>)
Initializes a new instance of the ChangeAwareList<T> class. Create a change aware list with the specified items.
public ChangeAwareList(IEnumerable<T> items)
Parameters
items
IEnumerable<T>The items to seed the change aware list with.
ChangeAwareList(int)
Initializes a new instance of the ChangeAwareList<T> class. Create a change aware list with the specified capacity.
public ChangeAwareList(int capacity = -1)
Parameters
capacity
intThe initial capacity of the internal lists.
Properties
Capacity
Gets or sets the total number of elements the internal data structure can hold without resizing.
public int Capacity { get; set; }
Property Value
Count
Gets the element count.
public int Count { get; }
Property Value
IsReadOnly
Gets a value indicating whether is this collection read only.
public bool IsReadOnly { get; }
Property Value
this[int]
Gets or sets the item at the specified index.
public T this[int index] { get; set; }
Parameters
index
intThe index to set.
Property Value
- T
Methods
Add(T)
Adds the item to the end of the collection.
public void Add(T item)
Parameters
item
TThe item to add.
AddRange(IEnumerable<T>)
Adds the elements of the specified collection to the end of the collection.
public void AddRange(IEnumerable<T> collection)
Parameters
collection
IEnumerable<T>The items to add.
Exceptions
- ArgumentNullException
collection
is null.
CaptureChanges()
Create a change set from recorded changes and clears known changes.
public IChangeSet<T> CaptureChanges()
Returns
- IChangeSet<T>
The change set.
Clear()
Removes all elements from the list.
public virtual void Clear()
Contains(T)
Determines whether the element is in the collection.
public virtual bool Contains(T item)
Parameters
item
TThe item to check.
Returns
- bool
If the item is contained or not.
CopyTo(T[], int)
Copies the entire collection to a compatible one-dimensional array, starting at the specified index of the target array.
public void CopyTo(T[] array, int arrayIndex)
Parameters
array
T[]The array to copy to.
arrayIndex
intThe index to start copying to.
GetEnumerator()
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
IndexOf(T)
Searches for the specified object and returns the zero-based index of the first occurrence within the entire collection.
public int IndexOf(T item)
Parameters
item
TThe item to get the index of.
Returns
- int
The index.
IndexOf(T, IEqualityComparer<T>)
Searches for the specified object and returns the zero-based index of the first occurrence within the entire collection, using the specified comparer.
public int IndexOf(T item, IEqualityComparer<T> equalityComparer)
Parameters
item
TThe item to get the index of.
equalityComparer
IEqualityComparer<T>The equality comparer to use to compare.
Returns
- int
The index.
Insert(int, T)
Inserts an element into the list at the specified index.
public void Insert(int index, T item)
Parameters
index
intThe index to insert at.
item
TThe item to insert.
InsertItem(int, T)
Inserts an item at the specified index.
protected virtual void InsertItem(int index, T item)
Parameters
index
intthe index where the item should be inserted.
item
TThe item to insert.
InsertRange(IEnumerable<T>, int)
Inserts the elements of a collection into the List<T> at the specified index.
public void InsertRange(IEnumerable<T> collection, int index)
Parameters
collection
IEnumerable<T>Inserts the specified items.
index
intThe zero-based index at which the new elements should be inserted.
Exceptions
- ArgumentNullException
collection
is null.- ArgumentOutOfRangeException
index
is less than 0.-or-index
is greater than Count.
Move(int, int)
Moves an item from the original to the destination index.
public virtual void Move(int original, int destination)
Parameters
Move(T, int)
Moves the item to the specified destination index.
public virtual void Move(T item, int destination)
Parameters
item
TThe item to move.
destination
intThe destination index.
OnInsertItems(int, IEnumerable<T>)
Override for custom Insert.
protected virtual void OnInsertItems(int startIndex, IEnumerable<T> items)
Parameters
startIndex
intThe starting index of the items being inserted.
items
IEnumerable<T>The items being inserted.
OnRemoveItems(int, IEnumerable<T>)
Override for custom remove.
protected virtual void OnRemoveItems(int startIndex, IEnumerable<T> items)
Parameters
startIndex
intThe starting index of the items being removed.
items
IEnumerable<T>The items being removed.
OnSetItem(int, T, T)
Override for custom Set.
protected virtual void OnSetItem(int index, T newItem, T oldItem)
Parameters
index
intThe index of the item set.
newItem
TThe new item.
oldItem
TThe old item.
Refresh(T)
Add a Refresh change for specified index to the list of changes. This is to notify downstream operators to refresh.
public bool Refresh(T item)
Parameters
item
TThe item to refresh.
Returns
- bool
If the item is in the list, returns true.
Refresh(T, int)
Add a Refresh change of the item at the specified index to the list of changes.
This is to notify downstream operators to refresh.
public void Refresh(T item, int index)
Parameters
item
TThe item to refresh.
index
intThe index to refresh.
RefreshAt(int)
Add a Refresh change of the item at the specified index to the list of changes.
This is to notify downstream operators to refresh.
public void RefreshAt(int index)
Parameters
index
intThe index to refresh.
Remove(T)
Removes the item from the collection and returns true if the item was successfully removed.
public bool Remove(T item)
Parameters
item
TThe item to remove.
Returns
- bool
If the item was removed.
RemoveAt(int)
Removes the item from the specified index.
public void RemoveAt(int index)
Parameters
index
intThe index to remove the item at.
RemoveItem(int)
Remove the item which is at the specified index.
protected void RemoveItem(int index)
Parameters
index
intThe index being removed.
RemoveItem(int, T)
Removes the item from the specified index - intended for internal use only.
protected virtual void RemoveItem(int index, T item)
Parameters
index
intThe index being removed.
item
TThe item being removed.
RemoveRange(int, int)
Removes a range of elements from the List<T>.
public void RemoveRange(int index, int count)
Parameters
index
intThe zero-based starting index of the range of elements to remove.
count
intThe number of elements to remove.
Exceptions
- ArgumentOutOfRangeException
index
is less than 0.-or-count
is less than 0.- ArgumentException
index
andcount
do not denote a valid range of elements in the List<T>.
SetItem(int, T)
Replaces the element which is as the specified index wth the specified item.
protected virtual void SetItem(int index, T item)
Parameters
index
intThe index of the item to set.
item
TThe item to set.