private void InvokeHandler(Type @interface, IHandleRegister bus, object executorInstance) { Type commandType = @interface.GetGenericArguments()[0]; MethodInfo registerExecutorMethod = bus .GetType() .GetMethods(BindingFlags.Instance | BindingFlags.Public) .Where(mi => mi.Name == "RegisterHandler") .Where(mi => mi.IsGenericMethod) .Where(mi => mi.GetGenericArguments().Count() == 1) .Where(mi => mi.GetParameters().Count() == 1) .Single() .MakeGenericMethod(commandType); var inmethod = executorInstance .GetType() .GetMethods(BindingFlags.Instance | BindingFlags.Public) .Where(mi => mi.Name == "Handle") .Where(mi => mi.GetParameters().Count() == 1) .Where(mi => mi.GetParameters().First().ParameterType == commandType) .Single(); var action = typeof(Action<>).MakeGenericType(commandType); var del = Delegate.CreateDelegate(action, executorInstance, inmethod); registerExecutorMethod.Invoke(bus, new[] { del }); }
private void InvokeHandler(Type @interface, IHandleRegister bus, object executorInstance) { Type commandType = @interface.GetGenericArguments()[0]; MethodInfo registerExecutorMethod = bus .GetType() .GetMethods(BindingFlags.Instance | BindingFlags.Public) .Where(mi => mi.Name == "RegisterHandler") .Where(mi => mi.IsGenericMethod) .Where(mi => mi.GetGenericArguments().Count() == 1) .Where(mi => mi.GetParameters().Count() == 1) .Single() .MakeGenericMethod(commandType); var inmethod = executorInstance .GetType() .GetMethods(BindingFlags.Instance | BindingFlags.Public) .Where(mi => mi.Name == "Handle") .Where(mi => mi.GetParameters().Count() == 1) .Where(mi => mi.GetParameters().First().ParameterType == commandType) .Single(); var action = typeof(Action <>).MakeGenericType(commandType); var del = Delegate.CreateDelegate(action, executorInstance, inmethod); registerExecutorMethod.Invoke(bus, new[] { del }); }
private void InvokeHandler(Type @interface, IHandleRegister bus, Type executorType) { var commandType = @interface.GetGenericArguments()[0]; var registerExecutorMethod = bus .GetType() .GetMethods(BindingFlags.Instance | BindingFlags.Public) .Where(mi => mi.Name == "RegisterHandler") .Where(mi => mi.IsGenericMethod) .Where(mi => mi.GetGenericArguments().Count() == 1) .Where(mi => mi.GetParameters().Count() == 1) .Single() .MakeGenericMethod(commandType); var del = new Action <dynamic>(x => { dynamic handler = _serviceLocator.GetService(executorType); handler.Handle(x); }); registerExecutorMethod.Invoke(bus, new[] { del }); }
private void InvokeHandler(Type @interface, IHandleRegister bus, Type executorType) { var commandType = @interface.GetGenericArguments()[0]; var registerExecutorMethod = bus .GetType() .GetMethods(BindingFlags.Instance | BindingFlags.Public) .Where(mi => mi.Name == "RegisterHandler") .Where(mi => mi.IsGenericMethod) .Where(mi => mi.GetGenericArguments().Count() == 1) .Where(mi => mi.GetParameters().Count() == 1) .Single() .MakeGenericMethod(commandType); var del = new Action<dynamic>(x => { dynamic handler = _serviceLocator.GetService(executorType); handler.Handle(x); }); registerExecutorMethod.Invoke(bus, new[] { del }); }