Class ImmutableDictionaryTransaction<TKey, TValue>
It is a class for transaction for System.Collections.Immutable.ImmutableDictionary<, >. It isn't immutable by itself. It is also not thread-safe and can be used from one thread.
It provides more effective way to make multiple modifications for System.Collections.Immutable.ImmutableDictionary<, > in transaction with tracking for all changes.
It behaves dictionary-like and implements most common dictionary methods.
You should use this class if you want to make multiple modifications to ThreadSafeDictionary<TKey, TValue>, but don't wanna to make them visible
until all of them completed. You should ensure no other modifications done in ThreadSafeDictionary<TKey, TValue> until transaction complete, because they may be overwritten.
Then you can create/re-use ImmutableDictionaryTransaction<TKey, TValue> and Start(ImmutableDictionary<TKey, TValue>) it for Snapshot.
When you done you can Commit() it and get new System.Collections.Immutable.ImmutableDictionary<, > with all modifications applied and then Set(ImmutableDictionary<TKey, TValue>) it back.
It may be extended if required to expose all modifications done in transaction for processing.
Inheritance
System.Object
ImmutableDictionaryTransaction<TKey, TValue>
Assembly: Eco.Core.dll
Syntax
public class ImmutableDictionaryTransaction<TKey, TValue> : Object
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
Constructors
ImmutableDictionaryTransaction()
Declaration
public ImmutableDictionaryTransaction()
Properties
Item[TKey]
Declaration
public TValue this[TKey key] { get; set; }
Parameters
Type |
Name |
Description |
TKey |
key |
|
Property Value
Methods
Add(TKey, TValue)
Declaration
public void Add(TKey key, TValue value)
Parameters
Type |
Name |
Description |
TKey |
key |
|
TValue |
value |
|
Commit()
Finishes transaction, clears transaction state and returns new System.Collections.Immutable.ImmutableDictionary<, > with all transaction changes applied.
Declaration
public ImmutableDictionary<TKey, TValue> Commit()
Returns
Type |
Description |
System.Collections.Immutable.ImmutableDictionary<TKey, TValue> |
|
ContainsKey(TKey)
Declaration
public bool ContainsKey(TKey key)
Parameters
Type |
Name |
Description |
TKey |
key |
|
Returns
Type |
Description |
System.Boolean |
|
Remove(TKey)
Declaration
public bool Remove(TKey key)
Parameters
Type |
Name |
Description |
TKey |
key |
|
Returns
Type |
Description |
System.Boolean |
|
RemoveRange(IEnumerable<TKey>)
Declaration
public void RemoveRange(IEnumerable<TKey> keys)
Parameters
Type |
Name |
Description |
System.Collections.Generic.IEnumerable<TKey> |
keys |
|
Start(ImmutableDictionary<TKey, TValue>)
Starts new transaction for initial
. Be sure you Commit() previous transaction, before this call, because state may not be clear!
Declaration
public void Start(ImmutableDictionary<TKey, TValue> initial)
Parameters
Type |
Name |
Description |
System.Collections.Immutable.ImmutableDictionary<TKey, TValue> |
initial |
|
TryGetValue(TKey, out TValue)
Declaration
public bool TryGetValue(TKey key, out TValue value)
Parameters
Type |
Name |
Description |
TKey |
key |
|
TValue |
value |
|
Returns
Type |
Description |
System.Boolean |
|
Extension Methods