Class ManagedConcurrentDictionary<TKey, TValue>
A ConcurrentDictonary that maps to the appropriate platform version.
Inheritance
Inherited Members
Namespace: FM.LiveSwitch
Assembly: FM.LiveSwitch.dll
Syntax
public class ManagedConcurrentDictionary<TKey, TValue>
where TValue : class
Type Parameters
Name | Description |
---|---|
TKey | |
TValue |
Constructors
ManagedConcurrentDictionary()
Creates a new instance.
Declaration
public ManagedConcurrentDictionary()
ManagedConcurrentDictionary(Function1<TKey, String>)
Creates a new ManagedConcurrentDictionary.
Declaration
public ManagedConcurrentDictionary(Function1<TKey, string> hashCallback)
Parameters
Type | Name | Description |
---|---|---|
Function1<TKey, System.String> | hashCallback | The hash function to use when the backing dictionary requires the key to be a string. |
Properties
Count
Gets the number of items in the dictionary.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
IsEmpty
Gets true if dictionary is empty.
Declaration
public bool IsEmpty { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Keys
Gets an array of keys.
Declaration
public ICollection<TKey> Keys { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<TKey> |
Values
Gets an array of Values.
Declaration
public ICollection<TValue> Values { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<TValue> |
Methods
AddOrUpdate(TKey, TValue)
Updates a value in the dictionary or adds it if it does not exist.
Declaration
public TValue AddOrUpdate(TKey key, TValue addValue)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to use for updating for adding. |
TValue | addValue | The value to be added for an absent key. |
Returns
Type | Description |
---|---|
TValue |
AddOrUpdate(TKey, TValue, Function2<TKey, TValue, TValue>)
Updates a value in the dictionary or adds it if it does not exist.
Declaration
public TValue AddOrUpdate(TKey key, TValue addValue, Function2<TKey, TValue, TValue> updateValueFactory)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to use for updating for adding. |
TValue | addValue | The value to be added for an absent key. |
Function2<TKey, TValue, TValue> | updateValueFactory | The function to use for generating a value based on an existing key. |
Returns
Type | Description |
---|---|
TValue |
Clear()
Clears the dictionary of all items.
Declaration
public void Clear()
ContainsKey(TKey)
True if the dictionary contains the key.
Declaration
public bool ContainsKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to check. |
Returns
Type | Description |
---|---|
System.Boolean |
GetOrAdd(TKey, Function1<TKey, TValue>)
Gets the value from the dictionary or adds a new one if it does not exist.
Declaration
public TValue GetOrAdd(TKey key, Function1<TKey, TValue> valueFactory)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to use when adding to the dictionary. |
Function1<TKey, TValue> | valueFactory | The Func that will create a value if needed. |
Returns
Type | Description |
---|---|
TValue | The dictionary value if exist, the value returned by the Func if not. |
TryAdd(TKey, TValue)
Tries to add a new value to the dictionary.
Declaration
public bool TryAdd(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to use when adding. |
TValue | value | The value to be added to the dictionary. |
Returns
Type | Description |
---|---|
System.Boolean | True if added, false if key already exists. |
TryGetValue(TKey, out TValue)
Tries to get a value from the dictionary.
Declaration
public bool TryGetValue(TKey key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | They key of the item to get form the dictionary. |
TValue | value | The value that was just received or null if failed. |
Returns
Type | Description |
---|---|
System.Boolean | True if succeeded. |
TryRemove(TKey)
Tries and removes a value from the dictionary.
Declaration
public bool TryRemove(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the item to remove. |
Returns
Type | Description |
---|---|
System.Boolean | True if successful. |
TryRemove(TKey, out TValue)
Tries and removes a value from the dictionary.
Declaration
public bool TryRemove(TKey key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the item to remove. |
TValue | value | The value that was just removed. |
Returns
Type | Description |
---|---|
System.Boolean | True if successful. |
TryUpdate(TKey, TValue, TValue)
Tries to update the value in the dictionary.
Declaration
public bool TryUpdate(TKey key, TValue newValue, TValue comparisonValue)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to use when updating. |
TValue | newValue | The new value. |
TValue | comparisonValue | The value to compare with the current value in the dictionary. |
Returns
Type | Description |
---|---|
System.Boolean | True if succeeded. |