コード例 #1
0
        /// <summary>
        /// Gets all attributes for a given Type.
        /// </summary>
        /// <typeparam name="TAttribute">The type of the attribute.</typeparam>
        /// <param name="type">The type.</param>
        /// <param name="property">The property.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>Returns a collection of Attributes</returns>
        public static IEnumerable <TAttribute> GetAttributes <TAttribute>(Type type, PropertyInfo property = null, Func <Attribute, bool> predicate = null)
            where TAttribute : Attribute
        {
            CachedTypeData cacheType = ReflectedCache.TypePropertyCache.GetOrAdd(type, new CachedTypeData(type));

            return(cacheType.GetAttributes <TAttribute>(property, predicate));
        }
コード例 #2
0
        /// <summary>
        /// Gets the type of the attributes for.
        /// </summary>
        /// <typeparam name="TAttribute">The type of the attribute.</typeparam>
        /// <typeparam name="TType">The type of the type.</typeparam>
        /// <param name="type">The type.</param>
        /// <param name="property">The property.</param>
        /// <param name="predicate">The predicate.</param>
        /// <returns>Returns a collection of Attributes</returns>
        public static IEnumerable <TAttribute> GetAttributes <TAttribute, TType>(TType type, PropertyInfo property = null, Func <TAttribute, bool> predicate = null)
            where TAttribute : Attribute
            where TType : class
        {
            Type           desiredType = type == null ? typeof(TType) : type.GetType();
            CachedTypeData cacheType   = ReflectedCache.TypePropertyCache.GetOrAdd(desiredType, new CachedTypeData(desiredType));

            return(cacheType.GetAttributes <TAttribute>(property, predicate));
        }