PropertyDictionary Class
Provides a thread-safe dictionary of properties.
public class PropertyDictionary
- Inheritance:
- object object
Constructors
PropertyDictionary()
Initializes an instance of the class.
public PropertyDictionary()
Properties
this[object]
Gets or sets the value of the property with the specified key.
[C#] In C#, this property is the indexer for the PropertyDictionary
class.
public object this[object key] { get; set; }
Parameter | Type | Description |
---|---|---|
key | object | The property key for which to search. |
Property Value
- object:
The value of the property with the specified key.
Keys
Gets the collection of property keys that have been registered in this dictionary.
public ReadOnlyCollection<object> Keys { get; }
Property Value
- ReadOnlyCollection<object>:
The collection of property keys that have been registered in this dictionary.
Methods
Add(object, object)
Adds a property to the dictionary.
public void Add(object key, object value)
Parameter | Type | Description |
---|---|---|
key | object | A key that identifies the property. |
value | object | The property value. |
ContainsKey(object)
Returns whether the dictionary contains a property with the specified key.
public bool ContainsKey(object key)
Parameter | Type | Description |
---|---|---|
key | object | The property key for which to search. |
Returns
- bool:
true
if the dictionary contains a property with the specified key; otherwise,false
.
GetOrCreateSingleton<TValue>(Creator<TValue>)
Returns a property value if found; otherwise, uses a specified delegate to create a new instance.
public TValue GetOrCreateSingleton<TValue>(PropertyDictionary.Creator<TValue> creator)
- Type Parameters:
-
TValue
-The type of property value.
Parameter | Type | Description |
---|---|---|
creator | PropertyDictionary.Creator<TValue> | A delegate that is used to create a new value instance if the property is not yet found. |
Returns
- TValue:
The singleton property value.
Remarks
This overload uses the TValue
Type
as the property key for which to search.
GetOrCreateSingleton<TValue>(object, Creator<TValue>)
Returns a property value if found; otherwise, uses a specified delegate to create a new instance.
public TValue GetOrCreateSingleton<TValue>(object key, PropertyDictionary.Creator<TValue> creator)
- Type Parameters:
-
TValue
-The type of property value.
Parameter | Type | Description |
---|---|---|
key | object | The property key for which to search. |
creator | PropertyDictionary.Creator<TValue> | A delegate that is used to create a new value instance if the property is not yet found. |
Returns
- TValue:
The singleton property value.
Remove(object)
Removes the property with the specified key from the dictionary.
public bool Remove(object key)
Parameter | Type | Description |
---|---|---|
key | object | The key of the property to remove. |
Returns
- bool:
true
if a property was removed; otherwise,false
.
TryGetValue<TValue>(object, out TValue)
Attempts to return the value of the property with the specified key.
public bool TryGetValue<TValue>(object key, out TValue value)
- Type Parameters:
-
TValue
-The type of property value.
Parameter | Type | Description |
---|---|---|
key | object | The property key for which to search. |
value | TValue | Returns the property value. |
Returns
- bool:
true
if a value was returned; otherwise,false
.