Class ObservableCollectionEx<T>
Observable collection with ability to delay or suspend CollectionChanged notifications
Inheritance
Implements
Inherited Members
Namespace: Simplic.Framework.DBUI
Assembly: Simplic.Framework.DBUI.dll
Syntax
[Serializable]
public class ObservableCollectionEx<T> : Collection<T>, IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged, IDisposable
Type Parameters
Name | Description |
---|---|
T |
Constructors
| Improve this Doc View SourceObservableCollectionEx()
Initializes a new instance of ObservableCollectionEx that is empty and has default initial capacity.
Declaration
public ObservableCollectionEx()
ObservableCollectionEx(ObservableCollectionEx<T>, Boolean)
Constructor that configures the container to delay or disable notifications.
Declaration
public ObservableCollectionEx(ObservableCollectionEx<T> parent, bool notify)
Parameters
Type | Name | Description |
---|---|---|
ObservableCollectionEx<T> | parent | Reference to an original collection whos events are being postponed |
System.Boolean | notify | Specifies if notifications needs to be delayed or disabled |
ObservableCollectionEx(IEnumerable<T>)
Initializes a new instance of the ObservableCollection class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied.
Declaration
public ObservableCollectionEx(IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | collection | The collection whose elements are copied to the new list. |
Remarks
The elements are copied onto the ObservableCollection in the same order they are read by the enumerator of the collection.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | collection is a null reference |
ObservableCollectionEx(List<T>)
Initializes a new instance of the ObservableCollectionEx class that contains elements copied from the specified list
Declaration
public ObservableCollectionEx(List<T> list)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<T> | list | The list whose elements are copied to the new list. |
Remarks
The elements are copied onto the ObservableCollectionEx in the same order they are read by the enumerator of the list.
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | list is a null reference |
Methods
| Improve this Doc View SourceAddRange(IEnumerable<T>)
Declaration
public void AddRange(IEnumerable<T> dataToAdd)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | dataToAdd |
BlockReentrancy()
Disallow reentrant attempts to change this collection. E.g. a event handler of the CollectionChanged event is not allowed to make changes to this collection.
Declaration
protected IDisposable BlockReentrancy()
Returns
Type | Description |
---|---|
System.IDisposable |
Remarks
typical usage is to wrap e.g. a OnCollectionChanged call with a using() scope:
using (BlockReentrancy())
{
CollectionChanged(this, new NotifyCollectionChangedEventArgs(action, item, index));
}
CheckReentrancy()
Check and assert for reentrant attempts to change this collection.
Declaration
protected void CheckReentrancy()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | raised when changing the collection while another collection change is still being notified to other listeners |
ClearItems()
Called by base class Collection<T> when the list is being cleared; raises a CollectionChanged event to any listeners.
Declaration
protected override void ClearItems()
Overrides
DelayNotifications()
Declaration
public ObservableCollectionEx<T> DelayNotifications()
Returns
Type | Description |
---|---|
ObservableCollectionEx<T> |
DisableNotifications()
Declaration
public ObservableCollectionEx<T> DisableNotifications()
Returns
Type | Description |
---|---|
ObservableCollectionEx<T> |
Dispose()
Called by the application code to fire all delayed notifications.
Declaration
public void Dispose()
Dispose(Boolean)
Fires notification with all accumulated events
Declaration
protected virtual void Dispose(bool reason)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | reason | True is called by App code. False if called from GC. |
Finalize()
Distructor
Declaration
protected void Finalize()
InsertItem(Int32, T)
Called by base class Collection<T> when an item is added to list; raises a CollectionChanged event to any listeners.
Declaration
protected override void InsertItem(int index, T item)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
T | item |
Overrides
Move(Int32, Int32)
Move item at oldIndex to newIndex.
Declaration
public void Move(int oldIndex, int newIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | oldIndex | |
System.Int32 | newIndex |
MoveItem(Int32, Int32)
Called by base class ObservableCollection<T> when an item is to be moved within the list; raises a CollectionChanged event to any listeners.
Declaration
protected virtual void MoveItem(int oldIndex, int newIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | oldIndex | |
System.Int32 | newIndex |
OnCollectionChanged(NotifyCollectionChangedEventArgs)
Raise CollectionChanged event to any listeners. Properties/methods modifying this ObservableCollection will raise a collection changed event through this virtual method.
Declaration
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Specialized.NotifyCollectionChangedEventArgs | e |
Remarks
When overriding this method, either call its base implementation or call BlockReentrancy() to guard against reentrant collection changes.
OnPropertyChanged(PropertyChangedEventArgs)
Raises a PropertyChanged event (per System.ComponentModel.INotifyPropertyChanged).
Declaration
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
System.ComponentModel.PropertyChangedEventArgs | e |
RemoveItem(Int32)
Called by base class Collection<T> when an item is removed from list; raises a CollectionChanged event to any listeners.
Declaration
protected override void RemoveItem(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index |
Overrides
SetItem(Int32, T)
Called by base class Collection<T> when an item is set in list; raises a CollectionChanged event to any listeners.
Declaration
protected override void SetItem(int index, T item)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | |
T | item |
Overrides
Events
| Improve this Doc View SourceCollectionChanged
Occurs when the collection changes, either by adding or removing an item.
Declaration
protected virtual event NotifyCollectionChangedEventHandler CollectionChanged
Event Type
Type | Description |
---|---|
System.Collections.Specialized.NotifyCollectionChangedEventHandler |
Remarks
See System.Collections.Specialized.INotifyCollectionChanged
PropertyChanged
PropertyChanged event System.ComponentModel.INotifyPropertyChanged.
Declaration
protected virtual event PropertyChangedEventHandler PropertyChanged
Event Type
Type | Description |
---|---|
System.ComponentModel.PropertyChangedEventHandler |
Explicit Interface Implementations
| Improve this Doc View SourceINotifyCollectionChanged.CollectionChanged
Occurs when the collection changes, either by adding or removing an item.
Declaration
event NotifyCollectionChangedEventHandler INotifyCollectionChanged.CollectionChanged
Returns
Type | Description |
---|---|
System.Collections.Specialized.NotifyCollectionChangedEventHandler |
Remarks
see System.Collections.Specialized.INotifyCollectionChanged
INotifyPropertyChanged.PropertyChanged
PropertyChanged event (per System.ComponentModel.INotifyPropertyChanged).
Declaration
event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
Returns
Type | Description |
---|---|
System.ComponentModel.PropertyChangedEventHandler |