Class SerializedSwiftBiDictionary<TLeft, TRight>
- Namespace
- SwiftCollections.Unity
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
TLeftA Unity-serializable left key type.
TRightA 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
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
leftTLeftThe 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
leftTLeftThe left key to add.
rightTRightThe right key to add.
Returns
- bool
truewhen both keys were added; otherwisefalse.
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
leftTLeftThe left key to find.
Returns
- bool
truewhen the left key exists; otherwisefalse.
ContainsValue(TRight)
Returns whether the bi-dictionary contains the right key.
public bool ContainsValue(TRight right)
Parameters
rightTRightThe right key to find.
Returns
- bool
truewhen the right key exists; otherwisefalse.
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
itemsSerializedSwiftBiDictionaryEntry<TLeft, TRight>[]The two-way mappings to persist.
Exceptions
- ArgumentNullException
itemsis null.- InvalidOperationException
itemscontains 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
rightTRightThe right key to find.
leftTLeftThe associated left key when found.
Returns
- bool
truewhen the right key exists; otherwisefalse.
TryGetValue(TLeft, out TRight)
Attempts to get the right value associated with the left key.
public bool TryGetValue(TLeft left, out TRight right)
Parameters
leftTLeftThe left key to find.
rightTRightThe associated right value when found.
Returns
- bool
truewhen the left key exists; otherwisefalse.