Beispiel #1
0
 internal ClassBasedCommandOption(ClassBasedCommandOptionMetadata commandOptionMetadata, ICommand command)
 {
     _commandOptionMetadata = commandOptionMetadata;
     _command     = command;
     _miAddMethod = _commandOptionMetadata.PropertyOption.PropertyType.GetMethod("Add");
     if (!string.IsNullOrEmpty(Metadata.DefaultValue))
     {
         AssignValue(Metadata.DefaultValue);
     }
 }
 private static IEnumerable <ClassBasedCommandOptionMetadata> ExtractCommandOptions(Type commandType, ICommandMetadata commandMetadata, List <IConverter> converters, List <IPropertyOptionAlternateNameGenerator> optionAlternateNameGenerators)
 {
     foreach (var propertyInfo in commandType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(pi => pi.Name != nameof(ICommand.Arguments)))
     {
         var commandOption = ClassBasedCommandOptionMetadata.Create(propertyInfo, commandMetadata, converters, optionAlternateNameGenerators);
         if (commandOption != null)
         {
             yield return(commandOption);
         }
     }
 }
        internal static ClassBasedCommandOptionMetadata Create(PropertyInfo propertyInfo, ICommandMetadata commandMetadata, List <IConverter> converters, IEnumerable <IPropertyOptionAlternateNameGenerator> optionAlternateNameGenerators)
        {
            Guard.NotNull(propertyInfo, nameof(propertyInfo));
            Guard.NotNull(commandMetadata, nameof(commandMetadata));
            Guard.NotNull(converters, nameof(converters));
            Guard.NotNull(optionAlternateNameGenerators, nameof(optionAlternateNameGenerators));

            if (propertyInfo.ShouldBeIgnored())
            {
                return(null);
            }
            if (!propertyInfo.IsValidOptionProperty())
            {
                throw new CommandLineParserException(
                          Constants.ExceptionMessages.ParserExtractMetadataPropertyShouldBeWritableOrICollection(
                              propertyInfo.Name, commandMetadata.Name));
            }
            var commandOption = new ClassBasedCommandOptionMetadata(propertyInfo, commandMetadata, converters, optionAlternateNameGenerators);

            return(commandOption);
        }