Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    PropertyContainer Struct

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

    Name Description
    Constructors
    PropertyContainer(Object)
    Properties
    Count

    Gets the number of properties stored in this container.

    IsReadOnly
    Item[PropertyKey]
    Keys
    Owner
    Values
    Methods
    Add<T>(PropertyKey<T>, T)

    Adds the specified key-value pair.

    AddAccessorProperty(Type, PropertyKey)
    Clear()
    ContainsKey(PropertyKey)

    Determines whether the specified instance contains this key.

    CopyTo(ref PropertyContainer)

    Copies properties from this instance to a container.

    Get(PropertyKey)

    Gets the specified tag value.

    Get<T>(PropertyKey<T>)

    Gets the specified tag value.

    GetEnumerator()

    Gets the key-properties value pairs in this instance.

    GetSafe<T>(PropertyKey<T>)

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

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

    Sets the specified tag value.

    SetObject(PropertyKey, Object)

    Sets the specified tag value.

    TryGetValue(PropertyKey, out Object)

    Tries to get a tag value.

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

    Tries to get a tag value.

    Events
    PropertyUpdated

    Occurs when a property is modified.

    Explicit Interface Implementations
    ICollection<KeyValuePair<PropertyKey, Object>>.Add(KeyValuePair<PropertyKey, Object>)
    ICollection<KeyValuePair<PropertyKey, Object>>.Contains(KeyValuePair<PropertyKey, Object>)
    ICollection<KeyValuePair<PropertyKey, Object>>.CopyTo(KeyValuePair<PropertyKey, Object>[], Int32)
    ICollection<KeyValuePair<PropertyKey, Object>>.Remove(KeyValuePair<PropertyKey, Object>)
    IDictionary<PropertyKey, Object>.Add(PropertyKey, Object)
    IReadOnlyDictionary<PropertyKey, Object>.Keys
    IReadOnlyDictionary<PropertyKey, Object>.Values
    IEnumerable.GetEnumerator()
    | Improve this Doc View Source

    Constructors


    PropertyContainer(Object)

    public PropertyContainer(object owner)
    Parameters
    Type Name Description
    System.Object owner
    | Improve this Doc View Source

    Properties


    Count

    Gets the number of properties stored in this container.

    public readonly int Count { get; }
    Property Value
    Type Description
    System.Int32

    The count of properties.


    IsReadOnly

    public readonly bool IsReadOnly { get; }
    Property Value
    Type Description
    System.Boolean

    Item[PropertyKey]

    public object this[PropertyKey key] { get; set; }
    Parameters
    Type Name Description
    PropertyKey key
    Property Value
    Type Description
    System.Object

    Keys

    public readonly ICollection<PropertyKey> Keys { get; }
    Property Value
    Type Description
    System.Collections.Generic.ICollection<PropertyKey>

    Owner

    public readonly object Owner { get; }
    Property Value
    Type Description
    System.Object

    Values

    public readonly ICollection<object> Values { get; }
    Property Value
    Type Description
    System.Collections.Generic.ICollection<System.Object>
    | Improve this Doc View Source

    Methods


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

    Adds the specified key-value pair.

    public void Add<T>(PropertyKey<T> key, T value)
    Parameters
    Type Name Description
    PropertyKey<T> key

    The key.

    T value

    The value.

    Type Parameters
    Name Description
    T

    Type of the property key


    AddAccessorProperty(Type, PropertyKey)

    public static void AddAccessorProperty(Type type, PropertyKey propertyKey)
    Parameters
    Type Name Description
    System.Type type
    PropertyKey propertyKey

    Clear()

    public void Clear()

    ContainsKey(PropertyKey)

    Determines whether the specified instance contains this key.

    public bool ContainsKey(PropertyKey key)
    Parameters
    Type Name Description
    PropertyKey key

    The key.

    Returns
    Type Description
    System.Boolean

    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
    Type Name Description
    PropertyContainer destination

    The destination.


    Get(PropertyKey)

    Gets the specified tag value.

    public object Get(PropertyKey propertyKey)
    Parameters
    Type Name Description
    PropertyKey propertyKey

    The tag property.

    Returns
    Type Description
    System.Object

    Value of the tag property


    Get<T>(PropertyKey<T>)

    Gets the specified tag value.

    public T Get<T>(PropertyKey<T> propertyKey)
    Parameters
    Type Name Description
    PropertyKey<T> propertyKey

    The tag property.

    Returns
    Type Description
    T

    Typed value of the tag property

    Type Parameters
    Name Description
    T

    Type of the tag value


    GetEnumerator()

    Gets the key-properties value pairs in this instance.

    public IEnumerator<KeyValuePair<PropertyKey, object>> GetEnumerator()
    Returns
    Type Description
    System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<PropertyKey, System.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
    Type Name Description
    PropertyKey<T> propertyKey

    The property key.

    Returns
    Type Description
    T

    The value associated with this property key.

    Type Parameters
    Name Description
    T

    Type of the property key

    Exceptions
    Type Condition
    System.ArgumentNullException

    propertyKey

    System.ArgumentException

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


    Remove(PropertyKey)

    public bool Remove(PropertyKey propertyKey)
    Parameters
    Type Name Description
    PropertyKey propertyKey
    Returns
    Type Description
    System.Boolean

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

    Sets the specified tag value.

    public void Set<T>(PropertyKey<T> propertyKey, T tagValue)
    Parameters
    Type Name Description
    PropertyKey<T> propertyKey

    The tag property.

    T tagValue

    The tag value.

    Type Parameters
    Name Description
    T

    Type of the tag value


    SetObject(PropertyKey, Object)

    Sets the specified tag value.

    public void SetObject(PropertyKey propertyKey, object tagValue)
    Parameters
    Type Name Description
    PropertyKey propertyKey

    The tag property.

    System.Object tagValue

    The tag value.


    TryGetValue(PropertyKey, out Object)

    Tries to get a tag value.

    public bool TryGetValue(PropertyKey propertyKey, out object value)
    Parameters
    Type Name Description
    PropertyKey propertyKey

    The tag property.

    System.Object value

    The value or default vaue if not found

    Returns
    Type Description
    System.Boolean

    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
    Type Name Description
    PropertyKey<T> propertyKey

    The tag property.

    T value

    The value or default vaue if not found

    Returns
    Type Description
    System.Boolean

    Returns true if the was found; false otherwise

    Type Parameters
    Name Description
    T

    Type of the tag value

    | Improve this Doc View Source

    Events


    PropertyUpdated

    Occurs when a property is modified.

    public event PropertyContainer.PropertyUpdatedDelegate PropertyUpdated
    Event Type
    Type Description
    PropertyContainer.PropertyUpdatedDelegate
    | Improve this Doc View Source

    Explicit Interface Implementations


    ICollection<KeyValuePair<PropertyKey, Object>>.Add(KeyValuePair<PropertyKey, Object>)

    void ICollection<KeyValuePair<PropertyKey, object>>.Add(KeyValuePair<PropertyKey, object> item)
    Parameters
    Type Name Description
    System.Collections.Generic.KeyValuePair<PropertyKey, System.Object> item

    ICollection<KeyValuePair<PropertyKey, Object>>.Contains(KeyValuePair<PropertyKey, Object>)

    bool ICollection<KeyValuePair<PropertyKey, object>>.Contains(KeyValuePair<PropertyKey, object> item)
    Parameters
    Type Name Description
    System.Collections.Generic.KeyValuePair<PropertyKey, System.Object> item
    Returns
    Type Description
    System.Boolean

    ICollection<KeyValuePair<PropertyKey, Object>>.CopyTo(KeyValuePair<PropertyKey, Object>[], Int32)

    void ICollection<KeyValuePair<PropertyKey, object>>.CopyTo(KeyValuePair<PropertyKey, object>[] array, int arrayIndex)
    Parameters
    Type Name Description
    System.Collections.Generic.KeyValuePair<PropertyKey, System.Object>[] array
    System.Int32 arrayIndex

    ICollection<KeyValuePair<PropertyKey, Object>>.Remove(KeyValuePair<PropertyKey, Object>)

    bool ICollection<KeyValuePair<PropertyKey, object>>.Remove(KeyValuePair<PropertyKey, object> item)
    Parameters
    Type Name Description
    System.Collections.Generic.KeyValuePair<PropertyKey, System.Object> item
    Returns
    Type Description
    System.Boolean

    IDictionary<PropertyKey, Object>.Add(PropertyKey, Object)

    void IDictionary<PropertyKey, object>.Add(PropertyKey key, object value)
    Parameters
    Type Name Description
    PropertyKey key
    System.Object value

    IReadOnlyDictionary<PropertyKey, Object>.Keys

    readonly IEnumerable<PropertyKey> IReadOnlyDictionary<PropertyKey, object>.Keys { get; }
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<PropertyKey>

    IReadOnlyDictionary<PropertyKey, Object>.Values

    readonly IEnumerable<object> IReadOnlyDictionary<PropertyKey, object>.Values { get; }
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<System.Object>

    IEnumerable.GetEnumerator()

    IEnumerator IEnumerable.GetEnumerator()
    Returns
    Type Description
    System.Collections.IEnumerator

    Inherited Members

    System.ValueType.Equals(System.Object)
    System.ValueType.GetHashCode()
    System.ValueType.ToString()

    Extension Methods

    ComponentBaseExtensions.DisposeBy<T>(T, ICollectorHolder)
    ComponentBaseExtensions.RemoveDisposeBy<T>(T, ICollectorHolder)
    ArrayExtensions.ComputeHash<T>(ICollection<T>, IEqualityComparer<T>)
    EnumerableExtensions.IsNullOrEmpty(IEnumerable)
    EnumerableExtensions.ForEach<T>(IEnumerable, Action<T>)
    EnumerableExtensions.ForEach<T>(IEnumerable<T>, Action<T>)
    EnumerableExtensions.IndexOf<T>(IEnumerable<T>, Func<T, Boolean>)
    EnumerableExtensions.LastIndexOf<T>(IEnumerable<T>, Func<T, Boolean>)
    • Improve this Doc
    • View Source
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation