Ejemplo n.º 1
0
        private CommandType FindCommandType(string[] args)
        {
            Assembly    appAssembly = GetType().Assembly;
            List <Type> argTypes    = Arguments.Count > 0
                ? Arguments
                : appAssembly.GetTypes().Where(t => t.Name.EndsWith("Args")).ToList();

            _argumentMatcher = new ArgumentMatcher
            {
                Types = argTypes
            };

            var allTypes = appAssembly.GetTypes().ToList();

            Type argsType = null;

            try
            {
                argsType = _argumentMatcher.Match(args);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Type commandType = FindMatchingCommandType(allTypes, argsType);

            if (commandType != null)
            {
                return(new CommandType
                {
                    Command = commandType,
                    Args = argsType
                });
            }

            if (commandType == null && argsType != null)
            {
                throw new NotImplementedException(
                          string.Format("No class with an Execute-method with the class '{0}' as argument could be found",
                                        argsType.Name));
            }

            return(null);
        }
Ejemplo n.º 2
0
 public CommandExecutable(string[] args, CommandType commandType, ArgumentMatcher argumentMatcher)
 {
     _commandType     = commandType;
     _argumentMatcher = argumentMatcher;
     _commandSet      = CreateCommandWithArgs(args, commandType);
 }