diff --git a/src/HookExecutor.cs b/src/HookExecutor.cs index 478997c..b5aea9c 100644 --- a/src/HookExecutor.cs +++ b/src/HookExecutor.cs @@ -32,8 +32,7 @@ public HookExecutor(IAssemblyLoader assemblyLoader, IReflectionWrapper reflectio _executionInfoMapper = mapper; } - public async Task Execute(string hookType, IHooksStrategy strategy, - IList applicableTags, + public async Task Execute(string hookType, IHooksStrategy strategy, IList applicableTags, ExecutionInfo info) { var methods = GetHookMethods(hookType, strategy, applicableTags); @@ -47,7 +46,7 @@ public async Task Execute(string hookType, IHooksStrategy strat try { var context = _executionInfoMapper.ExecutionContextFrom(info); - await Execute(methodInfo, context); + await ExecuteHook(methodInfo, context); } catch (Exception ex) { @@ -62,14 +61,32 @@ public async Task Execute(string hookType, IHooksStrategy strat return executionResult; } - + + private async Task ExecuteHook(MethodInfo method, params object[] objects) + { + if (HasArguments(method, objects)) + await Execute(method, objects); + else + await Execute(method); + } + + + private static bool HasArguments(MethodInfo method, object[] args) + { + if (method.GetParameters().Length != args.Length) + return false; + return !args.Where((t, i) => t.GetType() != method.GetParameters()[i].ParameterType).Any(); + } + + private IEnumerable GetHookMethods(string hookType, IHooksStrategy strategy, IEnumerable applicableTags) { var hooksFromRegistry = GetHooksFromRegistry(hookType); return strategy.GetApplicableHooks(applicableTags, hooksFromRegistry); } - + + private IEnumerable GetHooksFromRegistry(string hookType) { _registry = _registry ?? new HookRegistry(_assemblyLoader);