private static void SetupActionHandler(ControllerBase instance) { foreach (MethodInfo method in instance.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy)) { IEnumerable <TargetActionAttribute> targetAttributes = method.GetCustomAttributes <TargetActionAttribute>(true); if (targetAttributes.Count() > 0) { ControllerActionDelegate actionHandler = (ControllerActionDelegate)method.CreateDelegate(typeof(ControllerActionDelegate), instance); foreach (TargetActionAttribute actionAttribute in targetAttributes) { if (actionAttribute.Actions == null || actionAttribute.Actions.Count() == 0) //catch all for that target component { instance.actionHandlers.Add(string.Empty, actionHandler); } else //catch dedicated target/method(s) { foreach (string action in actionAttribute.Actions) { instance.actionHandlers.Add($"{action.ToUpperInvariant()}", actionHandler); } } } } } }
public ControllerAction(Method method, string path, ControllerActionDelegate action) : base(method, path) { this.Action = action; }