Beispiel #1
0
        private void AddModuleInternal <TModule>(ModuleModel module, IModuleConfiguration <TModule> config)
        {
            module.Name                   = config.Name;
            module.Description            = config.Description;
            module.ExcludeFromCommandName = config.ExcludeFromCommandName;

            var newCommands = new List <CommandModel>();
            var methods     = module.Type.GetTypeInfo().GetMethods();

            foreach (var method in methods)
            {
                if (config.IsRemoved(method))
                {
                    continue;
                }

                if (_commandConstructor.TryCreate(method, module, out var command))
                {
                    var result = _commandValidator.Validate(command);
                    if (!result.IsValid)
                    {
                        throw new InvalidCommandException(command, result.Errors);
                    }

                    module.Commands.Add(command);
                    newCommands.Add(command);
                }
            }

            // TODO: test for command duplicates

            _commands.AddRange(newCommands);
        }