Table of Contents

Class SwiftObservableArray<TValue>

Namespace
SwiftCollections.Observable
Assembly
SwiftCollections.dll

Represents an array of observable properties, raising events whenever an element is updated. Designed for performance-critical scenarios in Unity game development.

[JsonConverter(typeof(StateJsonConverterFactory))]
[MemoryPackable(GenerateType.Object)]
public class SwiftObservableArray<TValue> : IStateBacked<SwiftArrayState<TValue>>, INotifyPropertyChanged, IMemoryPackable<SwiftObservableArray<TValue>>, IMemoryPackFormatterRegister

Type Parameters

TValue

The type of elements in the array.

Inheritance
SwiftObservableArray<TValue>
Implements
IStateBacked<SwiftArrayState<TValue>>
IMemoryPackable<SwiftObservableArray<TValue>>
IMemoryPackFormatterRegister
Inherited Members

Remarks

MemoryPack GenerateType: Object

SwiftCollections.SwiftArrayState<TValue> State

Constructors

SwiftObservableArray(SwiftObservableProperty<TValue>[])

Initializes a new instance of the SwiftObservableArray class with the specified observable properties.

public SwiftObservableArray(SwiftObservableProperty<TValue>[] observableProperties)

Parameters

observableProperties SwiftObservableProperty<TValue>[]

An array of SwiftObservableProperty<TValue> instances to be managed by the array. Cannot be null.

Remarks

Each property in the array is assigned its index and subscribed to change notifications. Changes to any property will be observed by the array.

SwiftObservableArray(SwiftArrayState<TValue>)

Initializes a new instance of the SwiftObservableArray<TValue> class with the specified SwiftArrayState<T>.

[MemoryPackConstructor]
public SwiftObservableArray(SwiftArrayState<TValue> state)

Parameters

state SwiftArrayState<TValue>

The state containing the internal array, count, offset, and version for initialization.

SwiftObservableArray(int)

Initializes a new instance of the SwiftObservableArray class with the specified capacity.

public SwiftObservableArray(int capacity)

Parameters

capacity int

The number of elements the array can contain. Must be a positive integer.

Remarks

Each element in the array is initialized with a new SwiftObservableProperty<TValue> instance. The capacity determines the fixed size of the array and cannot be changed after construction.

Fields

_itemChangedHandler

Represents the event handler that is invoked when a property value changes on an item.

protected PropertyChangedEventHandler _itemChangedHandler

Field Value

PropertyChangedEventHandler

Remarks

This handler is typically used to subscribe to property change notifications for items within a collection or container. Derived classes can use this field to manage event subscriptions for item property changes.

_items

Represents the collection of observable properties managed by this instance.

protected SwiftObservableProperty<TValue>[] _items

Field Value

SwiftObservableProperty<TValue>[]

Remarks

Each element in the array corresponds to an individual observable property. The array may be null or empty if no properties are currently managed.

Properties

Capacity

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

[JsonIgnore]
[MemoryPackIgnore]
public int Capacity { get; }

Property Value

int

this[int]

Gets or sets the value at the specified index.

[JsonIgnore]
[MemoryPackIgnore]
public TValue this[int index] { get; set; }

Parameters

index int

The zero-based index of the element to get or set. Must be within the valid range of the collection.

Property Value

TValue

State

Gets or sets the current state of the array, including the values of all items.

[JsonInclude]
[MemoryPackInclude]
public SwiftArrayState<TValue> State { get; }

Property Value

SwiftArrayState<TValue>

Remarks

Setting this property replaces the entire array state, including all item values and their order. Any existing item change handlers are reset when the state is set.

Methods

ToArray()

Returns an array containing all elements in the collection.

public TValue[] ToArray()

Returns

TValue[]

An array of type TValue that contains the values of the collection in order. The array will be empty if the collection contains no elements.

Events

ElementChanged

Raised when any element in the array changes, providing the index and the new value.

public event EventHandler<SwiftObservableArray<TValue>.ElementChangedEventArgs<TValue>>? ElementChanged

Event Type

EventHandler<SwiftObservableArray<TValue>.ElementChangedEventArgs<TValue>>

PropertyChanged

Raised when the array's state changes.

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler