Class SwiftObservableList<T>
- Namespace
- SwiftCollections.Observable
- Assembly
- SwiftCollections.dll
Represents an observable extension of the high-performance SwiftList<T>. Notifies listeners of changes to its items and structure for reactive programming scenarios.
[JsonConverter(typeof(StateJsonConverterFactory))]
[MemoryPackable(GenerateType.Object)]
public class SwiftObservableList<T> : SwiftList<T>, ISwiftCloneable<T>, IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable, IMemoryPackable<SwiftList<T>>, IStateBacked<SwiftArrayState<T>>, INotifyPropertyChanged, INotifyCollectionChanged, IMemoryPackable<SwiftObservableList<T>>, IMemoryPackFormatterRegister
Type Parameters
TThe type of elements in the list.
- Inheritance
-
SwiftList<T>SwiftObservableList<T>
- Implements
-
IList<T>ICollection<T>IEnumerable<T>IMemoryPackable<SwiftList<T>>IStateBacked<SwiftArrayState<T>>IMemoryPackable<SwiftObservableList<T>>IMemoryPackFormatterRegister
- Inherited Members
- Extension Methods
Remarks
MemoryPack GenerateType: Object
SwiftCollections.SwiftArrayState<T> State
Constructors
SwiftObservableList()
Initializes a new instance of the SwiftObservableList<T> class.
public SwiftObservableList()
SwiftObservableList(SwiftArrayState<T>)
Initializes a new instance of the SwiftObservableList<T> class with the specified SwiftArrayState<T>.
[MemoryPackConstructor]
public SwiftObservableList(SwiftArrayState<T> state)
Parameters
stateSwiftArrayState<T>The state containing the internal array, count, offset, and version for initialization.
SwiftObservableList(IEnumerable<T>)
Initializes a new instance of the SwiftObservableList<T> class that contains elements copied from the specified collection.
public SwiftObservableList(IEnumerable<T> collection)
Parameters
collectionIEnumerable<T>
SwiftObservableList(int)
Initializes a new instance of the SwiftObservableList<T> class with the specified initial capacity.
public SwiftObservableList(int capacity)
Parameters
capacityint
Properties
this[int]
Sets or gets the element at the specified index. Raises collection change notifications on modification.
[JsonIgnore]
[MemoryPackIgnore]
public T this[int index] { get; set; }
Parameters
indexint
Property Value
- T
Methods
Add(T)
Adds an element to the end of the list. Raises collection and property change notifications.
public override void Add(T item)
Parameters
itemT
AddRange(IEnumerable<T>)
Adds the elements of the specified collection to the end of the current collection.
public override void AddRange(IEnumerable<T> items)
Parameters
itemsIEnumerable<T>The collection whose elements should be added to the end of the collection. Cannot be null.
Remarks
Known-count sources reserve capacity before enumeration while preserving per-item notifications.
AddRange(ReadOnlySpan<T>)
Adds the elements of the specified span to the end of the list. Raises collection and property change notifications for each added item.
public override void AddRange(ReadOnlySpan<T> items)
Parameters
itemsReadOnlySpan<T>
AddRange(T[])
Adds the elements of the specified array to the end of the list. Raises collection and property change notifications for each added item.
public override void AddRange(T[] items)
Parameters
itemsT[]
Clear()
Clears all elements from the list. Raises a reset collection change notification.
public override void Clear()
Insert(int, T)
Inserts an element into the list at the specified index. Raises collection and property change notifications.
public override void Insert(int index, T item)
Parameters
indexintitemT
OnCollectionChanged(NotifyCollectionChangedEventArgs)
Raises the CollectionChanged event for the specified action and items.
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs args)
Parameters
OnPropertyChanged(string)
Raises the PropertyChanged event.
protected virtual void OnPropertyChanged(string propertyName)
Parameters
propertyNamestringThe name of the property that changed.
Remove(T)
Removes the first occurrence of a specific object from the list. Raises collection and property change notifications.
public override bool Remove(T item)
Parameters
itemT
Returns
RemoveAll(Predicate<T>)
Removes all elements from the collection that match the conditions defined by the specified predicate.
public override int RemoveAll(Predicate<T> match)
Parameters
matchPredicate<T>The delegate that defines the conditions of the elements to remove. Cannot be null.
Returns
- int
The number of elements removed from the collection.
Remarks
Raises a collection changed event with the Reset action and notifies property changes if any elements are removed. This method is useful when you need to remove multiple items based on a condition and notify observers of the change.
RemoveAt(int)
Removes the element at the specified index. Raises collection and property change notifications.
public override void RemoveAt(int index)
Parameters
indexint
Events
CollectionChanged
Raised when the list's collection is modified.
public event NotifyCollectionChangedEventHandler? CollectionChanged
Event Type
PropertyChanged
Raised when a property on the list changes.
public event PropertyChangedEventHandler? PropertyChanged