/// <summary>
        /// Gets a set of route factories for the given action descriptor.
        /// </summary>
        /// <param name="actionDescriptor">The action descriptor.</param>
        /// <returns>A set of route factories.</returns>
        /// <remarks>
        /// The implementation returns <see cref="IDirectRouteFactory"/> instances based on attributes on the action. Returns
        /// null if the action was defined on a base class of this controller.
        /// </remarks>
        protected virtual IReadOnlyList<IDirectRouteFactory> GetActionRouteFactories(ActionDescriptor actionDescriptor)
        {
            // Skip Route attributes on inherited actions.
            IMethodInfoActionDescriptor methodInfoActionDescriptor = actionDescriptor as IMethodInfoActionDescriptor;
            if (methodInfoActionDescriptor != null &&
                methodInfoActionDescriptor.MethodInfo != null &&
                actionDescriptor.ControllerDescriptor != null &&
                methodInfoActionDescriptor.MethodInfo.DeclaringType != actionDescriptor.ControllerDescriptor.ControllerType)
            {
                return null;
            }

            object[] attributes = actionDescriptor.GetCustomAttributes(inherit: false);
            IEnumerable<IDirectRouteFactory> newFactories = attributes.OfType<IDirectRouteFactory>();
            IEnumerable<IRouteInfoProvider> oldProviders = attributes.OfType<IRouteInfoProvider>();

            List<IDirectRouteFactory> combined = new List<IDirectRouteFactory>();
            combined.AddRange(newFactories);

            foreach (IRouteInfoProvider oldProvider in oldProviders)
            {
                if (oldProvider is IDirectRouteFactory)
                {
                    continue;
                }

                combined.Add(new RouteInfoDirectRouteFactory(oldProvider));
            }

            return combined;
        }
 public static IEnumerable <string> GetActionCustomAttributes(this ActionDescriptor action)
 {
     return(action?.GetCustomAttributes(typeof(CustomAuthorizeAttribute), true)
            .Cast <CustomAuthorizeAttribute>()
            .SelectMany(attributes => attributes?.Roles ?? Array.Empty <string>()));
 }
 /// <summary>
 /// Returns specified attributes for an action descriptor.
 /// </summary>
 /// <param name="call">The call.</param>
 /// <returns>Returns specified attributes for an action method along with the action's controller.</returns>
 public static TAttribute[] GetAttributes <TAttribute>(this ActionDescriptor action)
 {
     return(action.GetCustomAttributes(typeof(TAttribute), true)
            .Cast <TAttribute>()
            .ToArray());
 }
 private IEnumerable <AgentAuthorizeAttribute> GetAgentAuthorizeAttributes(ActionDescriptor descriptor)
 {
     return(descriptor.GetCustomAttributes(typeof(AgentAuthorizeAttribute), true)
            .Concat(descriptor.ControllerDescriptor.GetCustomAttributes(typeof(AgentAuthorizeAttribute), true))
            .OfType <AgentAuthorizeAttribute>());
 }
Esempio n. 5
0
        //Treats the action as if it is decorated with Route attribute
        protected override IReadOnlyList <IDirectRouteFactory> GetActionRouteFactories(ActionDescriptor actionDescriptor)
        {
            var publiclyRoutable = actionDescriptor.GetCustomAttributes(typeof(PublicRouteAttribute), false).Any();

            return(publiclyRoutable ? new[] { new RouteAttribute(actionDescriptor.ActionName) } : null);
        }
Esempio n. 6
0
        /// <summary>
        /// 获取 Action 显示名称
        /// </summary>
        /// <param name="x"></param>
        /// <returns></returns>
        public static string GetDisplayName(this ActionDescriptor x)
        {
            var attr = x.GetCustomAttributes(typeof(DisplayAttribute), true).FirstOrDefault();

            return(attr != null ? ((DisplayAttribute)attr).Name : null);
        }
Esempio n. 7
0
 private static bool ValidationDisabled(ActionDescriptor actionDescriptor)
 {
     return(actionDescriptor.GetCustomAttributes(typeof(SkipAjaxValidation), false).Cast <SkipAjaxValidation>().Any());
 }
Esempio n. 8
0
 private static IEnumerable <AdminAttribute> GetAdminAttributes(ActionDescriptor descriptor)
 {
     return(descriptor.GetCustomAttributes(typeof(AdminAttribute), true)
            .Concat(descriptor.ControllerDescriptor.GetCustomAttributes(typeof(AdminAttribute), true))
            .OfType <AdminAttribute>());
 }
 public static T GetCustomAttribute <T>(this ActionDescriptor actionDescriptor) where T : Attribute
 {
     return(Cache.GetOrAdd(actionDescriptor.UniqueId, k =>
                           actionDescriptor.GetCustomAttributes(typeof(T), true).SingleOrDefault() ??
                           actionDescriptor.ControllerDescriptor.GetCustomAttributes(typeof(T), true).SingleOrDefault()) as T);
 }
 public bool ActionHasAttribute <TAttribute>(ActionDescriptor actionDescriptor) where TAttribute : Attribute
 {
     return(actionDescriptor
            .GetCustomAttributes(typeof(TAttribute), true)
            .Any());
 }
Esempio n. 11
0
 private bool IsAnonymousAction(ActionDescriptor actionDescriptor)
 {
     return(actionDescriptor.GetCustomAttributes(inherit: true).OfType <AllowAnonymousAttribute>().Any());
 }