Example #1
0
        /// <summary>
        /// Creates actions for the provided host.
        /// </summary>
        /// <param name="host">The host.</param>
        /// <returns></returns>
        public IEnumerable <IAction> CreateFor(IActionHost host)
        {
            var actions      = new List <IAction>();
            var methodGroups = SelectMethods(host.TargetType);

            foreach (var methodGroup in methodGroups)
            {
                var methodList = methodGroup.ToList();

                if (methodList.Count == 1)
                {
                    actions.Add(CreateAction(host, methodList[0]));
                }
                else
                {
                    var overloadedAction = new OverloadedAction(methodGroup.Key);

                    foreach (var methodInfo in methodList)
                    {
                        overloadedAction.AddOverload(CreateAction(host, methodInfo));
                    }

                    actions.Add(overloadedAction);
                }
            }

            return(actions);
        }
        /// <summary>
        /// Locates actions for the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>Discovered actions.</returns>
        public IEnumerable <IAction> Locate(ActionLocationContext context)
        {
            var actions      = new List <IAction>();
            var methodGroups = SelectMethods(context.TargetType);

            foreach (var methodGroup in methodGroups)
            {
                var methodList = methodGroup.ToList();

                if (methodList.Count == 1)
                {
                    actions.Add(CreateAction(context.TargetType, context.TargetFilters, methodList[0]));
                }
                else
                {
                    var overloadedAction = new OverloadedAction(methodGroup.Key);

                    foreach (var methodInfo in methodList)
                    {
                        overloadedAction.AddOverload(CreateAction(context.TargetType, context.TargetFilters, methodInfo));
                    }

                    actions.Add(overloadedAction);
                }
            }

            return(actions);
        }