public Executor(Type commandType, Type handlerType)
{
resultProperty = commandType.GetProperty("Result");
if (resultProperty != null)
{
var resultHandlerType = typeof (ICommandHandler<,>).MakeGenericType(commandType,
resultProperty.PropertyType);
if (resultHandlerType.IsAssignableFrom(handlerType))
{
executeResultMethod = resultHandlerType.GetMethod("Execute");
}
}
executeMethod = handlerType.GetMethod("Execute");
if (executeResultMethod != null)
{
ExecuteHandler =
(handler, command) =>
resultProperty.SetValue(command, executeResultMethod.Invoke(handler, new object[] {command}));
}
else
{
ExecuteHandler = (handler, command) => executeMethod.Invoke(handler, new object[] {command});
}
}