Table of Contents

Class SerializedSwiftBiDictionary<TLeft, TRight>

Unity-serializable adapter for persisted two-way lookup data consumed as a SwiftBiDictionary<T1, T2>.

[Serializable]
public sealed class SerializedSwiftBiDictionary<TLeft, TRight> : ISerializationCallbackReceiver where TLeft : notnull where TRight : notnull

Type Parameters

TLeft

A Unity-serializable left key type.

TRight

A Unity-serializable right key type.

Inheritance
SerializedSwiftBiDictionary<TLeft, TRight>
Implements
ISerializationCallbackReceiver
Inherited Members

Properties

Count

Gets the number of two-way mappings.

public int Count { get; }

Property Value

int

this[TLeft]

Gets or sets a right value by left key and updates the serialized backing entries.

public TRight this[TLeft left] { get; set; }

Parameters

left TLeft

The left key.

Property Value

TRight

The associated right value.

Runtime

Gets the live runtime bi-dictionary rebuilt from Unity serialized data.

public SwiftBiDictionary<TLeft, TRight> Runtime { get; }

Property Value

SwiftBiDictionary<TLeft, TRight>

Remarks

Direct runtime mutations are copied into serialized backing data before Unity serialization.

Methods

Add(TLeft, TRight)

Adds a two-way mapping and updates the serialized backing entries.

public bool Add(TLeft left, TRight right)

Parameters

left TLeft

The left key to add.

right TRight

The right key to add.

Returns

bool

true when both keys were added; otherwise false.

Clear()

Removes all mappings from the runtime bi-dictionary and serialized backing array.

public void Clear()

ContainsKey(TLeft)

Returns whether the bi-dictionary contains the left key.

public bool ContainsKey(TLeft left)

Parameters

left TLeft

The left key to find.

Returns

bool

true when the left key exists; otherwise false.

ContainsValue(TRight)

Returns whether the bi-dictionary contains the right key.

public bool ContainsValue(TRight right)

Parameters

right TRight

The right key to find.

Returns

bool

true when the right key exists; otherwise false.

GetEnumerator()

Returns an enumerator for the runtime bi-dictionary.

public SwiftDictionary<TLeft, TRight>.SwiftDictionaryEnumerator GetEnumerator()

Returns

SwiftDictionary<TLeft, TRight>.SwiftDictionaryEnumerator

A SwiftCollections dictionary enumerator.

OnAfterDeserialize()

Rebuilds runtime contents after Unity deserialization.

public void OnAfterDeserialize()

Exceptions

InvalidOperationException

Serialized entries contain duplicate left or right keys.

OnBeforeSerialize()

Copies live runtime contents into Unity's serialized backing data.

public void OnBeforeSerialize()

SetItems(params SerializedSwiftBiDictionaryEntry<TLeft, TRight>[])

Replaces the serialized contents with a copy of the supplied entries.

public void SetItems(params SerializedSwiftBiDictionaryEntry<TLeft, TRight>[] items)

Parameters

items SerializedSwiftBiDictionaryEntry<TLeft, TRight>[]

The two-way mappings to persist.

Exceptions

ArgumentNullException

items is null.

InvalidOperationException

items contains duplicate left or right keys.

ToArray()

Returns a copy of the serialized entries.

public SerializedSwiftBiDictionaryEntry<TLeft, TRight>[] ToArray()

Returns

SerializedSwiftBiDictionaryEntry<TLeft, TRight>[]

A new array containing the current mappings.

ToSwiftBiDictionary()

Returns a copy as a standalone SwiftBiDictionary<T1, T2>.

public SwiftBiDictionary<TLeft, TRight> ToSwiftBiDictionary()

Returns

SwiftBiDictionary<TLeft, TRight>

A new bi-dictionary containing the current mappings.

TryGetKey(TRight, out TLeft)

Attempts to get the left key associated with the right value.

public bool TryGetKey(TRight right, out TLeft left)

Parameters

right TRight

The right key to find.

left TLeft

The associated left key when found.

Returns

bool

true when the right key exists; otherwise false.

TryGetValue(TLeft, out TRight)

Attempts to get the right value associated with the left key.

public bool TryGetValue(TLeft left, out TRight right)

Parameters

left TLeft

The left key to find.

right TRight

The associated right value when found.

Returns

bool

true when the left key exists; otherwise false.