Aperea.Commands.CommandExecutor.CreateExecutor C# (CSharp) Метод

CreateExecutor() приватный статический Метод

private static CreateExecutor ( ICommand command, ICommandHandler handler ) : Executor
command ICommand
handler ICommandHandler
Результат Executor
        private static Executor CreateExecutor(ICommand command, ICommandHandler handler)
        {
            var commandType = command.GetType();
            foreach (var interfaceType in commandType.GetInterfaces())
            {
                if (interfaceType.IsGenericType && typeof (ICommand).IsAssignableFrom(interfaceType))
                {
                    var resultType = interfaceType.GetGenericArguments()[0];
                    var handlerType = typeof (ICommandHandler<,>).MakeGenericType(commandType, resultType);
                    if (handlerType.IsInstanceOfType(handler))
                    {
                        return new Executor(commandType, handlerType);
                    }
                }
                else if (typeof (ICommand).IsAssignableFrom(interfaceType))
                {
                    var handlerType = typeof (ICommandHandler<>).MakeGenericType(commandType);
                    return new Executor(commandType, handlerType);
                }
            }
            throw new InvalidOperationException(
                "don't create CommandHandlers which derives directory from ICommandHandler");
        }