예제 #1
0
        public CommandRegistration Register(string commandName, Type commandType)
        {
            var alreadyContains = Contains(commandType);

            if (alreadyContains)
            {
                return(null);
            }

            var isRealCommand = TypeUtils.IsAssignableToGenericType(commandType, typeof(ICommand <>));

            if (!isRealCommand)
            {
                throw new NotSupportedException(string.Format("Only types that implement {0} are allowed.", typeof(ICommand <>).FullName));
            }

            var implementedCommands = TypeUtils.ExtractCommandImplementationsFromType(commandType);

            if (implementedCommands.Length > 1)
            {
                var commandNames = string.Join(", ", implementedCommands.Select(x => x.FullName).ToArray());
                throw new NotSupportedException(string.Format("Type {0} implements more than one command which is not currently supported. It implements: {1}", commandType.FullName, commandNames));
            }

            var existingCommand = Find(commandName);

            if (existingCommand != null)
            {
                throw new Exception(string.Format("The command name \"{1}\" is already registered with command type {0}", existingCommand.FullName, commandName));
            }

            var registration = new CommandRegistration(
                commandName: commandName,
                commandType: TypeUtils.ExtractCommandImplementationsFromType(commandType).First(),
                argumentType: TypeUtils.ExtractArgumentTypesFromCommand(commandType).First(),
                implementationType: commandType
                );

            _commandTypes.Add(commandName, registration);

            return(registration);
        }
예제 #2
0
 protected bool Equals(CommandRegistration other)
 {
     return(string.Equals(CommandName, other.CommandName) && Equals(CommandType, other.CommandType) &&
            Equals(ArgumentType, other.ArgumentType) && Equals(ImplementationType, other.ImplementationType));
 }
예제 #3
0
 protected bool Equals(CommandRegistration other)
 {
     return string.Equals(CommandName, other.CommandName) && Equals(CommandType, other.CommandType) &&
            Equals(ArgumentType, other.ArgumentType) && Equals(ImplementationType, other.ImplementationType);
 }
예제 #4
0
        public CommandRegistration Register(string commandName, Type commandType)
        {
            var alreadyContains = Contains(commandType);
            if (alreadyContains)
            {
                return null;
            }

            var isRealCommand = TypeUtils.IsAssignableToGenericType(commandType, typeof(ICommand<>));
            if (!isRealCommand)
            {
                throw new NotSupportedException(string.Format("Only types that implement {0} are allowed.", typeof(ICommand<>).FullName));
            }

            var implementedCommands = TypeUtils.ExtractCommandImplementationsFromType(commandType);
            if (implementedCommands.Length > 1)
            {
                var commandNames = string.Join(", ", implementedCommands.Select(x => x.FullName).ToArray());
                throw new NotSupportedException(string.Format("Type {0} implements more than one command which is not currently supported. It implements: {1}", commandType.FullName, commandNames));
            }

            var existingCommand = Find(commandName);
            if (existingCommand != null)
            {
                throw new Exception(string.Format("The command name \"{1}\" is already registered with command type {0}", existingCommand.FullName, commandName));
            }

            var registration = new CommandRegistration(
                commandName: commandName,
                commandType: TypeUtils.ExtractCommandImplementationsFromType(commandType).First(),
                argumentType: TypeUtils.ExtractArgumentTypesFromCommand(commandType).First(),
                implementationType: commandType
                );

            _commandTypes.Add(commandName, registration);

            return registration;
        }