Unosquare
    Show / Hide Table of Contents

    Class AttributeCache

    A thread-safe cache of attributes belonging to a given key (MemberInfo or Type).

    The Retrieve method is the most useful one in this class as it calls the retrieval process if the type is not contained in the cache.

    Inheritance
    Object
    AttributeCache
    Inherited Members
    Object.ToString()
    Object.Equals(Object)
    Object.Equals(Object, Object)
    Object.ReferenceEquals(Object, Object)
    Object.GetHashCode()
    Object.GetType()
    Object.MemberwiseClone()
    Namespace: Swan.Reflection
    Syntax
    public class AttributeCache

    Constructors

    AttributeCache(PropertyTypeCache)

    Initializes a new instance of the AttributeCache class.

    Declaration
    public AttributeCache(PropertyTypeCache propertyCache = null)
    Parameters
    Type Name Description
    PropertyTypeCache propertyCache

    The property cache object.

    Properties

    DefaultCache

    Gets the default cache.

    Declaration
    public static Lazy<AttributeCache> DefaultCache { get; }
    Property Value
    Type Description
    Lazy<AttributeCache>

    The default cache.

    PropertyTypeCache

    A PropertyTypeCache object for caching properties and their attributes.

    Declaration
    public PropertyTypeCache PropertyTypeCache { get; }
    Property Value
    Type Description
    PropertyTypeCache

    Methods

    Contains<T>(MemberInfo)

    Determines whether [contains] [the specified member].

    Declaration
    public bool Contains<T>(MemberInfo member)
    Parameters
    Type Name Description
    MemberInfo member

    The member.

    Returns
    Type Description
    Boolean

    true if [contains] [the specified member]; otherwise, false.

    Type Parameters
    Name Description
    T

    The type of the attribute to be retrieved.

    Retrieve(MemberInfo, Type, Boolean)

    Gets all attributes of a specific type from a member.

    Declaration
    public IEnumerable<object> Retrieve(MemberInfo member, Type type, bool inherit = false)
    Parameters
    Type Name Description
    MemberInfo member

    The member.

    Type type

    The attribute type.

    Boolean inherit

    true to inspect the ancestors of element; otherwise, false.

    Returns
    Type Description
    IEnumerable<Object>

    An array of the attributes stored for the specified type.

    Retrieve<T>(MemberInfo, Boolean)

    Gets specific attributes from a member constrained to an attribute.

    Declaration
    public IEnumerable<object> Retrieve<T>(MemberInfo member, bool inherit = false)
        where T : Attribute
    Parameters
    Type Name Description
    MemberInfo member

    The member.

    Boolean inherit

    true to inspect the ancestors of element; otherwise, false.

    Returns
    Type Description
    IEnumerable<Object>

    An array of the attributes stored for the specified type.

    Type Parameters
    Name Description
    T

    The type of the attribute to be retrieved.

    Retrieve<T>(Type, Boolean)

    Gets all properties an their attributes of a given type constrained to only attributes.

    Declaration
    public Dictionary<PropertyInfo, IEnumerable<object>> Retrieve<T>(Type type, bool inherit = false)
        where T : Attribute
    Parameters
    Type Name Description
    Type type

    The type of the object.

    Boolean inherit

    true to inspect the ancestors of element; otherwise, false.

    Returns
    Type Description
    Dictionary<PropertyInfo, IEnumerable<Object>>

    A dictionary of the properties and their attributes stored for the specified type.

    Type Parameters
    Name Description
    T

    The type of the attribute to retrieve.

    RetrieveFromType<T>(Type, Boolean)

    Gets all properties and their attributes of a given type.

    Declaration
    public Dictionary<PropertyInfo, IEnumerable<object>> RetrieveFromType<T>(Type attributeType, bool inherit = false)
    Parameters
    Type Name Description
    Type attributeType

    Type of the attribute.

    Boolean inherit

    true to inspect the ancestors of element; otherwise, false.

    Returns
    Type Description
    Dictionary<PropertyInfo, IEnumerable<Object>>

    A dictionary of the properties and their attributes stored for the specified type.

    Type Parameters
    Name Description
    T

    The object type used to extract the properties from.

    RetrieveFromType<T, TAttribute>(Boolean)

    Gets all properties and their attributes of a given type.

    Declaration
    public Dictionary<PropertyInfo, IEnumerable<object>> RetrieveFromType<T, TAttribute>(bool inherit = false)
    Parameters
    Type Name Description
    Boolean inherit

    true to inspect the ancestors of element; otherwise, false.

    Returns
    Type Description
    Dictionary<PropertyInfo, IEnumerable<Object>>

    A dictionary of the properties and their attributes stored for the specified type.

    Type Parameters
    Name Description
    T

    The object type used to extract the properties from.

    TAttribute

    The type of the attribute.

    RetrieveOne<T>(MemberInfo, Boolean)

    Gets one attribute of a specific type from a member.

    Declaration
    public T RetrieveOne<T>(MemberInfo member, bool inherit = false)
        where T : Attribute
    Parameters
    Type Name Description
    MemberInfo member

    The member.

    Boolean inherit

    true to inspect the ancestors of element; otherwise, false.

    Returns
    Type Description
    T

    An attribute stored for the specified type.

    Type Parameters
    Name Description
    T

    The attribute type.

    RetrieveOne<TAttribute, T>(Boolean)

    Gets one attribute of a specific type from a generic type.

    Declaration
    public TAttribute RetrieveOne<TAttribute, T>(bool inherit = false)
        where TAttribute : Attribute
    Parameters
    Type Name Description
    Boolean inherit

    if set to true [inherit].

    Returns
    Type Description
    TAttribute

    An attribute stored for the specified type.

    Type Parameters
    Name Description
    TAttribute

    The type of the attribute.

    T

    The type to retrieve the attribute.

    Comments

    Back to top Copyright © 2017-2019 Unosquare