In This Article

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]

The value of the property with the specified key.

public object this[object key] { get; set; }
Parameter Type Description
key object

The property key for which to search.

Property Value

object

Keys

The collection of property keys that have been registered in this dictionary.

public ReadOnlyCollection<object> Keys { get; }

Property Value

ReadOnlyCollection<object>

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 TValueType 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

Outputs the property value.

Returns

bool:

true if a value was returned; otherwise, false.

TryGetValue<TValue>(out TValue?)

Attempts to return the value of the property where the key matches the type of the value to return.

public bool TryGetValue<TValue>(out TValue? value)
Type Parameters:
TValue -

The key and type of property value.

Parameter Type Description
value TValue

Outputs the property value.

Returns

bool:

true if a value was returned; otherwise, false.

Remarks

This method will only return values added with the desired Type as a key, and will not match on other property values added with a different key even if the property value is an instance of the desired type.

Inherited Members

Extension Methods