public IEnumerable <FilterAttribute> GetFilterAttributes()
        {
            if (ControllerType == null)
            {
                return(null);
            }

            return(ControllerType.GetCustomAttributes <FilterAttribute>());
        }
        /// <summary>
        /// Returns a collection of attributes that can be assigned to <typeparamref name="T"/> for this descriptor's controller.
        /// </summary>
        /// <remarks>The default implementation retrieves the matching set of attributes declared on <see cref="ControllerType"/>.</remarks>
        /// <typeparam name="T">Used to filter the collection of attributes. Use a value of <see cref="Object"/> to retrieve all attributes.</typeparam>
        /// <returns>A collection of attributes associated with this controller.</returns>
        public virtual Collection <T> GetCustomAttributes <T>() where T : class
        {
            // Getting custom attributes via reflection is slow.
            // But iterating over a object[] to pick out specific types is fast.
            // Furthermore, many different services may call to ask for different attributes, so we have multiple callers.
            // That means there's not a single cache for the callers, which means there's some value caching here.
            if (_attrCached == null)
            {
                // Even in a race, we'll just ask for the custom attributes twice.
                _attrCached = ControllerType.GetCustomAttributes(inherit: true);
            }

            return(new Collection <T>(TypeHelper.OfType <T>(_attrCached)));
        }
Exemple #3
0
 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
 {
     return(ControllerType.GetCustomAttributes(attributeType, inherit));
 }
 public object[] GetCustomAttributes(bool inherit)
 {
     return(ControllerType.GetCustomAttributes(inherit));
 }