Class ObjectDictionary
Describes dictionaries mapping case-sensitive strings to objects along with nice generic methods that converts item values to specific types.
Implements
Namespace: Neon.Collections
Assembly: Neon.Common.dll
Syntax
public class ObjectDictionary : Dictionary<string, object>, IObjectDictionary
Constructors
ObjectDictionary()
Constructor.
Declaration
public ObjectDictionary()
Methods
Get<TValue>(string)
Returns the value of an item converted to a specific type.
Declaration
public TValue Get<TValue>(string key)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key. |
Returns
Type | Description |
---|---|
TValue | The value converted to TValue. |
Type Parameters
Name | Description |
---|---|
TValue | The result type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if key is |
KeyNotFoundException | Thrown by the getter if the key doesn't exist. |
InvalidCastException | Thrown if the item value cannot be cast into a TValue. |
Get<TValue>(string, TValue)
Returns the value of an item converted to a specific type.
Declaration
public TValue Get<TValue>(string key, TValue @default = default)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key. |
TValue | default | Secifies the default value to return if the key doesn't exist. |
Returns
Type | Description |
---|---|
TValue | The value converted to TValue. |
Type Parameters
Name | Description |
---|---|
TValue | The result type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if key is |
InvalidCastException | Thrown if the item value cannot be cast into a TValue. |
TryGetValue<TValue>(string, out TValue)
Attempts to retrieve a specific value from the dictionary.
Declaration
public bool TryGetValue<TValue>(string key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
string | key | The key. |
TValue | value | Returns as the value when the key exists. |
Returns
Type | Description |
---|---|
bool |
|
Type Parameters
Name | Description |
---|---|
TValue | The result type. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException | Thrown if key is |