예제 #1
0
        private CommandModel FindCommand(string[] commandName)
        {
            var name    = _commandNameParser.Parse(String.Join(" ", commandName));
            var context = new Dictionary <string, object>();

            ContextHelper.SetCommandName(context, name.Parts as string[] ?? name.Parts.ToArray());

            return(_commandResolver.Resolve(context, _appModel.Commands));
        }
        private CommandModel CreateInternal(MethodInfo method, ModuleModel module)
        {
            var command = new CommandModel();

            command.Method = method;
            command.Module = module;

            bool excludeModuleName = String.IsNullOrWhiteSpace(module.Name) ||
                                     module.ExcludeFromCommandName;

            string name = null;
            var    attr = method.GetCustomAttribute <CommandAttribute>();

            if (attr == null)
            {
                name = method.Name;
            }
            else
            {
                name = attr.Name ?? method.Name;
                command.Description = attr.Description;
                if (attr.IsSetExcludeModuleName)
                {
                    excludeModuleName = attr.ExcludeModuleName;
                }
            }

            if (!excludeModuleName)
            {
                name = module.Name + " " + name;
            }
            command.Name = _commandNameParser.Parse(name);

            var parameters = method.GetParameters();
            var arguments  = new ArgumentModel[parameters.Length];

            command.Arguments = arguments;

            for (int i = 0; i < parameters.Length; i++)
            {
                arguments[i] = _argumentConstructor.Create(parameters[i], command);
            }

            return(command);
        }