private static IAction <IActionResult> GetActionInstacebyType(Type tp, ActionProcessor prmtrs) { if (!tp.GetConstructors().Any(c => c.GetParameters().Count() == 0)) { throw new ArgumentNullException(string.Format("The type {0} must hane a default constructor", tp.Name)); } int paramCnt = prmtrs == null ? 0 : 1; ConstructorInfo ctor = tp.GetConstructors().First(c => c.GetParameters().Count() == paramCnt); ObjectActivator <IAction <IActionResult> > createdActivator = GetActivator <IAction <IActionResult> >(ctor); return(createdActivator(prmtrs)); }
public static T Process <T>(IEnumerable <IActionParam> args, ActionProcesDelegate monitor = null) where T : IActionResult { var procc = new ActionProcessor(args); if (monitor != null) { procc.ProcessMonitor += monitor; } var res = procc.Process <T>(); if (monitor != null) { procc.ProcessMonitor -= monitor; } return(res); }
internal static IAction <IActionResult> GetAction(string actionId, ActionProcessor prmtrs) { FillActions(); if (actions.Keys.Any(k => k.Equals(actionId, StringComparison.InvariantCultureIgnoreCase))) { Type t = actions[actionId].ActionClassType; //Type t = actions.First(k => k.Key.Equals(actionId, StringComparison.InvariantCultureIgnoreCase)).Value.ActionClassType; var action = GetActionInstacebyType(t, prmtrs); if (action.Description.IsEmpty) { Logger.Instance.Warn(new ActionDescriptionNotDefinedException(action).Message); // throw new ActionDescriptionNotDefinedException(action); } return(action); } return(null); }