public IEnumerable<Type> GetDynamicVerbs(IEnumerable<string> path) { path = path.ToArray(); if (resultCache.ContainsKey(path)) { return resultCache[path]; } List<CommandDefinition> definitions = new List<CommandDefinition>(); foreach (IDynamicCommandProvider commandProvider in commandProviders) { definitions.AddRange(commandProvider.GetCommands(path)); } List<Type> types = new List<Type>(); Type baseType = null; if (createdTypes.ContainsKey(path) && createdTypes[path].GetCustomAttribute<UseChildVerbsAsCategoryAttribute>() == null) { baseType = createdTypes[path]; } foreach (CommandDefinition definition in definitions) { VerbTypeFactory builder = VerbTypeFactory.Create(definition.Name, definition.Help); if (baseType != null) { builder.SetBaseType(baseType); } if (definition.UseChildVerbsAsCategory) { builder.EnableUseChildVerbsAsCategory(); } foreach (Argument argument in definition.Arguments) { OptionValueType valueType; char separator = default(char); switch (argument) { case BoolArgument _: valueType = OptionValueType.WithoutValue; break; case SingleValueArgument _: valueType = OptionValueType.SingleValue; break; case MultipleValueArgument arg: valueType = OptionValueType.MultipleValue; separator = arg.Separator; break; default: throw new ArgumentException("Unknown value type."); } if(valueType == OptionValueType.MultipleValue) { builder.AddOption(argument.Name, argument.ShortName, argument.Mandatory, argument.Help, valueType, argument.SetName, separator); } else { builder.AddOption(argument.Name, argument.ShortName, argument.Mandatory, argument.Help, valueType, argument.SetName); } } foreach (CommandExample commandExample in definition.Examples) { builder.AddExample(commandExample.Command, commandExample.Description); } Type type = builder.Build(); types.Add(type); createdTypes.Add(path.Concat(new[] {definition.Name}).ToArray(), type); typeDefintionMatch.Add(type, definition); } resultCache.Add(path,types); return types; }
public void Dispose() { VerbTypeFactory.ClearStaticCaches(); }