Photon Server API

Public Member Functions | Protected Member Functions | Properties | List of all members
ExitGames.Threading.SynchronizedDictionary< TKey, TValue > Class Template Reference

Represents a thread-safe collection of key-value pairs that can be accessed by multiple threads concurrently. If using the Net 4.0 framework you should consider to use the new System.Collections.Concurrent.ConcurrentDictionary. The SynchronizedDictionary provides methods similar to the ConcurrentDictionary to provide a thread safe Dictionary for .NET 3.5 and earlier. More...

Inheritance diagram for ExitGames.Threading.SynchronizedDictionary< TKey, TValue >:

Public Member Functions

 SynchronizedDictionary ()
 Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class. More...
 
 SynchronizedDictionary (int capacity)
 Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class. More...
 
 SynchronizedDictionary (IEqualityComparer< TKey > comparer)
 Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class. More...
 
 SynchronizedDictionary (int capacity, IEqualityComparer< TKey > comparer)
 Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class. More...
 
 SynchronizedDictionary (IDictionary< TKey, TValue > dictionary)
 Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class. More...
 
 SynchronizedDictionary (IDictionary< TKey, TValue > dictionary, IEqualityComparer< TKey > comparer)
 Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class. More...
 
TValue AddOrUpdate (TKey key, TValue addValue, Func< TKey, TValue, TValue > updateValueFactory)
 Adds a key/value pair to the dictionary if the key does not already exist, or updates a key/value pair in the dictionary if the key already exists. More...
 
TValue AddOrUpdate (TKey key, Func< TKey, TValue > addValueFactory, Func< TKey, TValue, TValue > updateValueFactory)
 Adds a key/value pair to the dictionary if the key does not already exist, or updates a key/value pair in the dictionary if the key already exists. More...
 
void Clear ()
 Removes all keys and values from the SynchronizedDictionary<Key, TValue>. More...
 
bool ContainsKey (TKey key)
 Determines whether the SynchronizedDictionary<Key, TValue> contains the specified key. More...
 
TValue GetOrAdd (TKey key, Func< TKey, TValue > valueFactory)
 Adds a key/value pair to the SynchronizedDictionary<Key, TValue> if the key does not already exist More...
 
bool Remove (TKey key)
 Removes the value with the specified key from the SynchronizedDictionary<Key, TValue>. More...
 
bool TryAdd (TKey key, TValue value)
 Attempts to add the specified key and value to the SynchronizedDictionary<Key, TValue>. More...
 
bool TryGetValue (TKey key, out TValue value)
 Attempts to get the value associated with the specified key from the SynchronizedDictionary<Key, TValue>. More...
 
bool TryRemove (TKey key, out TValue value)
 Attempts to remove and return the value with the specified key from the SynchronizedDictionary<Key, TValue>. More...
 
bool TryUpdate (TKey key, TValue newValue, TValue comparisonValue)
 Compares the existing value for the specified key with a specified value, and if they are equal, updates the key with a third value. More...
 
void Dispose ()
 Releases all resources used by the current instance of the SynchronizedDictionary<TKey, TValue> class. More...
 

Protected Member Functions

virtual void Dispose (bool disposing)
 Releases unmanaged and - optionally - managed resources More...
 

Properties

int Count [get]
 Gets the number of key/value pairs contained in the SynchronizedDictionary<Key, TValue>. More...
 
TValue this[TKey key] [get, set]
 Gets or sets the value associated with the specified key. More...
 

Detailed Description

Represents a thread-safe collection of key-value pairs that can be accessed by multiple threads concurrently. If using the Net 4.0 framework you should consider to use the new System.Collections.Concurrent.ConcurrentDictionary. The SynchronizedDictionary provides methods similar to the ConcurrentDictionary to provide a thread safe Dictionary for .NET 3.5 and earlier.

Template Parameters
TKeyThe type of the keys in the dictionary.
TValueThe type of the values in the dictionary.

Constructor & Destructor Documentation

◆ SynchronizedDictionary() [1/6]

Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class.

◆ SynchronizedDictionary() [2/6]

ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.SynchronizedDictionary ( int  capacity)
inline

Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class.

Parameters
capacityThe initial number of elements that the SynchronizedDictionary can contain.

◆ SynchronizedDictionary() [3/6]

ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.SynchronizedDictionary ( IEqualityComparer< TKey >  comparer)
inline

Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class.

Parameters
comparerThe IEqualityComparer<TKey> implementation to use when comparing keys.

◆ SynchronizedDictionary() [4/6]

ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.SynchronizedDictionary ( int  capacity,
IEqualityComparer< TKey >  comparer 
)
inline

Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class.

Parameters
capacityThe initial number of elements that the SynchronizedDictionary can contain.
comparerThe IEqualityComparer<TKey> implementation to use when comparing keys.

◆ SynchronizedDictionary() [5/6]

ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.SynchronizedDictionary ( IDictionary< TKey, TValue >  dictionary)
inline

Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class.

Parameters
dictionaryThe IDictionary<TKey, TValue> whose elements are copied to the new SynchronizedDictionary.

◆ SynchronizedDictionary() [6/6]

ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.SynchronizedDictionary ( IDictionary< TKey, TValue >  dictionary,
IEqualityComparer< TKey >  comparer 
)
inline

Initializes a new instance of the SynchronizedDictionary<TKey,TValue> class. Initializes a new instance of the SynchronizedDictionary<TKey, TValue> class.

Parameters
dictionaryThe IDictionary<TKey, TValue> whose elements are copied to the new SynchronizedDictionary.
comparerThe IEqualityComparer<TKey> implementation to use when comparing keys.

Member Function Documentation

◆ AddOrUpdate() [1/2]

TValue ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.AddOrUpdate ( TKey  key,
Func< TKey, TValue >  addValueFactory,
Func< TKey, TValue, TValue >  updateValueFactory 
)
inline

Adds a key/value pair to the dictionary if the key does not already exist, or updates a key/value pair in the dictionary if the key already exists.

Parameters
keyThe key to be added or whose value should be updated.
addValueFactoryThe function used to generate a value for an absent key.
updateValueFactoryThe function used to generate a new value for an existing key based on the key's existing value.
Returns
The new value for the key. This will be either be the result of addValueFactory (if the key was absent) or the result of updateValueFactory (if the key was present).

◆ AddOrUpdate() [2/2]

TValue ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.AddOrUpdate ( TKey  key,
TValue  addValue,
Func< TKey, TValue, TValue >  updateValueFactory 
)
inline

Adds a key/value pair to the dictionary if the key does not already exist, or updates a key/value pair in the dictionary if the key already exists.

Parameters
keyThe key to be added or whose value should be updated.
addValueThe value to be added for an absent key.
updateValueFactoryThe function used to generate a new value for an existing key based on the key's existing value.
Returns
The new value for the key. This will be either be addValue (if the key was absent) or the result of updateValueFactory (if the key was present).

◆ Clear()

void ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.Clear ( )
inline

Removes all keys and values from the SynchronizedDictionary<Key, TValue>.

◆ ContainsKey()

bool ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.ContainsKey ( TKey  key)
inline

Determines whether the SynchronizedDictionary<Key, TValue> contains the specified key.

Parameters
keyThe key to locate.
Returns
True if the SynchronizedDictionary<Key, TValue> contains an element with the specified key; otherwise, false.

◆ Dispose() [1/2]

void ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.Dispose ( )
inline

Releases all resources used by the current instance of the SynchronizedDictionary<TKey, TValue> class.

◆ Dispose() [2/2]

virtual void ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.Dispose ( bool  disposing)
inlineprotectedvirtual

Releases unmanaged and - optionally - managed resources

Parameters
disposingtrue to release both managed and unmanaged resources; false to release only unmanaged resources.

Dispose(bool disposing) executes in two distinct scenarios. If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and unmanaged resources can be disposed. If disposing equals false, the method has been called by the runtime from inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed.

◆ GetOrAdd()

TValue ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.GetOrAdd ( TKey  key,
Func< TKey, TValue >  valueFactory 
)
inline

Adds a key/value pair to the SynchronizedDictionary<Key, TValue> if the key does not already exist

Parameters
keyThe key of the element to get or add.
valueFactoryThe function used to generate a value for the key
Returns
The value for the key. This will be either the existing value for the key if the key is already in the dictionary, or the new value for the key as returned by valueFactory if the key was not in the dictionary.

◆ Remove()

bool ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.Remove ( TKey  key)
inline

Removes the value with the specified key from the SynchronizedDictionary<Key, TValue>.

Parameters
keyThe key of the element to remove.
Returns
true if the element is successfully found and removed; otherwise, false. This method returns false if key is not found in the SynchronizedDictionary<Key, TValue>.

◆ TryAdd()

bool ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.TryAdd ( TKey  key,
TValue  value 
)
inline

Attempts to add the specified key and value to the SynchronizedDictionary<Key, TValue>.

Parameters
keyThe key of the element to add.
valueThe value of the element to add. The value can be a null reference (Nothing in Visual Basic) for reference types.
Returns
True if the key/value pair was added to the SynchronizedDictionary<Key, TValue> successfully. If the key already exists, this method returns false.

◆ TryGetValue()

bool ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.TryGetValue ( TKey  key,
out TValue  value 
)
inline

Attempts to get the value associated with the specified key from the SynchronizedDictionary<Key, TValue>.

Parameters
keyThe key of the value to get.
valueWhen this method returns true, value contains the object from the SynchronizedDictionary<Key, TValue> with the specified key.
Returns
true if the key was found in the SynchronizedDictionary<Key, TValue>; otherwise, false.

◆ TryRemove()

bool ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.TryRemove ( TKey  key,
out TValue  value 
)
inline

Attempts to remove and return the value with the specified key from the SynchronizedDictionary<Key, TValue>.

Parameters
keyThe key of the element to remove and return.
valueWhen this method returns true, value contains the object removed from the SynchronizedDictionary<Key, TValue> or the default value of if the operation failed.
Returns
true if an object was removed successfully; otherwise, false.

◆ TryUpdate()

bool ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.TryUpdate ( TKey  key,
TValue  newValue,
TValue  comparisonValue 
)
inline

Compares the existing value for the specified key with a specified value, and if they are equal, updates the key with a third value.

Parameters
keyThe key whose value is compared with comparisonValue and possibly replaced.
newValueThe value that replaces the value of the element with key if the comparison results in equality
comparisonValueThe value that is compared to the value of the element with key
Returns
true if the value with key was equal to comparisonValue and replaced with newValue; otherwise, false.

Property Documentation

◆ Count

int ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.Count
get

Gets the number of key/value pairs contained in the SynchronizedDictionary<Key, TValue>.

The number of key/value pairs contained in the SynchronizedDictionary<Key, TValue>

◆ this[TKey key]

TValue ExitGames.Threading.SynchronizedDictionary< TKey, TValue >.this[TKey key]
getset

Gets or sets the value associated with the specified key.

Parameters
keyThe key of the value to get or set.
Returns
The value for the key.