Table of Contents

Struct PropertyContainer

Namespace
Stride.Core
Assembly
Stride.Core.dll

Represents a container that can hold properties, lightweight to embed (lazy initialized).

[DataContract]
[DataSerializer(typeof(DictionaryAllSerializer<PropertyContainer, PropertyKey, object>))]
public struct PropertyContainer : IDictionary<PropertyKey, object>, ICollection<KeyValuePair<PropertyKey, object>>, IReadOnlyDictionary<PropertyKey, object>, IReadOnlyCollection<KeyValuePair<PropertyKey, object>>, IEnumerable<KeyValuePair<PropertyKey, object>>, IEnumerable
Implements
Inherited Members
Extension Methods

Remarks

Tag properties system purpose is to allow binding of properties that aren't logically supposed to be in a general class (probably because the property exists only in a higher level part of the engine). A typical example includes source mesh, collision data and various bouding volumes for a Geometry object: including them directly in the low-level Geometry class would be a terrible design decision ! And the other well known solution, which consist of maintaining a Dictionary of object to properties isn't really nice either (especially with non-deterministic object destruction, it's hard to clean it up, would require lot of events). As a result, a specific system has been implemented. A class that could hold such tag properties should have an instance of PropertyContainer as a mutable field member. An cool feature of this system is that if a property doesn't exist, it could be generated during first access from a delegate or come from a default value.

Constructors

PropertyContainer(object)

public PropertyContainer(object owner)

Parameters

owner object

Properties

Count

Gets the number of properties stored in this container.

public int Count { get; }

Property Value

int

The count of properties.

IsReadOnly

Gets a value indicating whether the ICollection<T> is read-only.

public bool IsReadOnly { get; }

Property Value

bool

true if the ICollection<T> is read-only; otherwise, false.

this[PropertyKey]

Gets or sets the element with the specified key.

public object this[PropertyKey key] { get; set; }

Parameters

key PropertyKey

The key of the element to get or set.

Property Value

object

The element with the specified key.

Exceptions

ArgumentNullException

key is null.

KeyNotFoundException

The property is retrieved and key is not found.

NotSupportedException

The property is set and the IDictionary<TKey, TValue> is read-only.

Keys

Gets an ICollection<T> containing the keys of the IDictionary<TKey, TValue>.

public ICollection<PropertyKey> Keys { get; }

Property Value

ICollection<PropertyKey>

An ICollection<T> containing the keys of the object that implements IDictionary<TKey, TValue>.

Owner

public readonly object Owner { get; }

Property Value

object

Values

Gets an ICollection<T> containing the values in the IDictionary<TKey, TValue>.

public ICollection<object> Values { get; }

Property Value

ICollection<object>

An ICollection<T> containing the values in the object that implements IDictionary<TKey, TValue>.

Methods

AddAccessorProperty(Type, PropertyKey)

public static void AddAccessorProperty(Type type, PropertyKey propertyKey)

Parameters

type Type
propertyKey PropertyKey

Add<T>(PropertyKey<T>, T)

Adds the specified key-value pair.

public void Add<T>(PropertyKey<T> key, T value)

Parameters

key PropertyKey<T>

The key.

value T

The value.

Type Parameters

T

Type of the property key

Clear()

Removes all items from the ICollection<T>.

public void Clear()

Exceptions

NotSupportedException

The ICollection<T> is read-only.

ContainsKey(PropertyKey)

Determines whether the specified instance contains this key.

public bool ContainsKey(PropertyKey key)

Parameters

key PropertyKey

The key.

Returns

bool

true if the specified instance contains this key; otherwise, false.

CopyTo(ref PropertyContainer)

Copies properties from this instance to a container.

public void CopyTo(ref PropertyContainer destination)

Parameters

destination PropertyContainer

The destination.

Get(PropertyKey)

Gets the specified tag value.

public object Get(PropertyKey propertyKey)

Parameters

propertyKey PropertyKey

The tag property.

Returns

object

Value of the tag property

GetEnumerator()

Gets the key-properties value pairs in this instance.

public IEnumerator<KeyValuePair<PropertyKey, object>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<PropertyKey, object>>

GetSafe<T>(PropertyKey<T>)

Gets the value of a property key or throw an error if the value was not found

public T GetSafe<T>(PropertyKey<T> propertyKey)

Parameters

propertyKey PropertyKey<T>

The property key.

Returns

T

The value associated with this property key.

Type Parameters

T

Type of the property key

Exceptions

ArgumentNullException

propertyKey

ArgumentException

Unable to retrieve value for [{0}].ToFormat(propertyKey)

Get<T>(PropertyKey<T>)

Gets the specified tag value.

public T Get<T>(PropertyKey<T> propertyKey)

Parameters

propertyKey PropertyKey<T>

The tag property.

Returns

T

Typed value of the tag property

Type Parameters

T

Type of the tag value

Remove(PropertyKey)

Removes the element with the specified key from the IDictionary<TKey, TValue>.

public bool Remove(PropertyKey propertyKey)

Parameters

propertyKey PropertyKey

Returns

bool

true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original IDictionary<TKey, TValue>.

Exceptions

ArgumentNullException

key is null.

NotSupportedException

The IDictionary<TKey, TValue> is read-only.

SetObject(PropertyKey, object)

Sets the specified tag value.

public void SetObject(PropertyKey propertyKey, object tagValue)

Parameters

propertyKey PropertyKey

The tag property.

tagValue object

The tag value.

Set<T>(PropertyKey<T>, T)

Sets the specified tag value.

public void Set<T>(PropertyKey<T> propertyKey, T tagValue)

Parameters

propertyKey PropertyKey<T>

The tag property.

tagValue T

The tag value.

Type Parameters

T

Type of the tag value

TryGetValue(PropertyKey, out object)

Tries to get a tag value.

public bool TryGetValue(PropertyKey propertyKey, out object value)

Parameters

propertyKey PropertyKey

The tag property.

value object

The value or default vaue if not found

Returns

bool

Returns true if the was found; false otherwise

TryGetValue<T>(PropertyKey<T>, out T)

Tries to get a tag value.

public bool TryGetValue<T>(PropertyKey<T> propertyKey, out T value)

Parameters

propertyKey PropertyKey<T>

The tag property.

value T

The value or default vaue if not found

Returns

bool

Returns true if the was found; false otherwise

Type Parameters

T

Type of the tag value

Events

PropertyUpdated

Occurs when a property is modified.

public event PropertyContainer.PropertyUpdatedDelegate PropertyUpdated

Event Type

PropertyContainer.PropertyUpdatedDelegate