Esempio n. 1
0
 public void AddCommand(CommandDescriptor commandDescriptor)
 {
     foreach (var name in commandDescriptor.GetNames(options))
     {
         if (subCommandDescriptors.ContainsKey(name) || !descriptors.TryAdd(name, commandDescriptor))
         {
             throw new InvalidOperationException($"Duplicate command name is added. Name:{name} Method:{commandDescriptor.MethodInfo.DeclaringType?.Name}.{commandDescriptor.MethodInfo.Name}");
         }
     }
 }
Esempio n. 2
0
        public void AddSubCommand(string parentCommand, CommandDescriptor commandDescriptor)
        {
            if (descriptors.ContainsKey(parentCommand))
            {
                throw new InvalidOperationException($"Duplicate parent-command is added. Name:{parentCommand} Method:{commandDescriptor.MethodInfo.DeclaringType?.Name}.{commandDescriptor.MethodInfo.Name}");
            }

            if (!subCommandDescriptors.TryGetValue(parentCommand, out var commandDict))
            {
                commandDict = new Dictionary <string, CommandDescriptor>(StringComparer.OrdinalIgnoreCase);
                subCommandDescriptors.Add(parentCommand, commandDict);
            }

            foreach (var name in commandDescriptor.GetNames(options))
            {
                if (!commandDict.TryAdd(name, commandDescriptor))
                {
                    throw new InvalidOperationException($"Duplicate command name is added. Name:{parentCommand} {name} Method:{commandDescriptor.MethodInfo.DeclaringType?.Name}.{commandDescriptor.MethodInfo.Name}");
                }
            }
        }