private CommandOption(PropertyInfo propertyInfo, CommandMetadata commandMetadata, IEnumerable<IConverter> converters)
 {
     PropertyOption = propertyInfo;
     CommandMetadata = commandMetadata;
     DisplayInfo = propertyInfo.ExtractOptionDisplayInfoMetadata();
     IsRequired = propertyInfo.ExtractIsRequiredMetadata();
     Converter = propertyInfo.ExtractConverter(converters, DisplayInfo.Name, CommandMetadata.Name);
     DefaultValue = propertyInfo.ExtractDefaultValue(ConvertValue);
     _miAddMethod = PropertyOption.PropertyType.GetMethod("Add");
 }
Ejemplo n.º 2
0
 private CommandOption(PropertyInfo propertyInfo, CommandMetadata commandMetadata, IEnumerable <IConverter> converters)
 {
     PropertyOption  = propertyInfo;
     CommandMetadata = commandMetadata;
     DisplayInfo     = propertyInfo.ExtractOptionDisplayInfoMetadata();
     IsRequired      = propertyInfo.ExtractIsRequiredMetadata();
     Converter       = propertyInfo.ExtractConverter(converters, DisplayInfo.Name, CommandMetadata.Name);
     DefaultValue    = propertyInfo.ExtractDefaultValue(ConvertValue);
     _miAddMethod    = PropertyOption.PropertyType.GetMethod("Add");
 }
Ejemplo n.º 3
0
 private static IEnumerable<CommandOption> ExtractCommandOptions(Type commandType, CommandMetadata commandMetadata, IEnumerable<IConverter> converters)
 {
     foreach (var propertyInfo in commandType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(pi => pi.Name != nameof(ICommand.Arguments)))
     {
         var commandOption = CommandOption.Create(propertyInfo, commandMetadata, converters);
         if (commandOption != null)
         {
             yield return commandOption;
         }
     }
 }
            public void TestListProperty()
            {
                // Arrange
                var propertyInfo = GetType()
                    .GetProperty(TypeHelpers.ExtractPropertyName(() => ListIntProperty));
                var commandMetadata = new CommandMetadata(typeof (GetMultiValueIndicator));
                var commandOption = CommandOption.Create(propertyInfo, commandMetadata, new[] {new Int32Converter()});
                var expected = HelpCommand.CollectionIndicator;

                // Act
                var actual = HelpCommand.GetMultiValueIndicator(commandOption);

                // Assert
                Assert.Equal(expected, actual);
            }
Ejemplo n.º 5
0
        internal static CommandOption Create(PropertyInfo propertyInfo, CommandMetadata commandMetadata, IEnumerable <IConverter> converters)
        {
            Guard.NotNull(propertyInfo, nameof(propertyInfo));
            Guard.NotNull(commandMetadata, nameof(commandMetadata));
            Guard.NotNull(converters, nameof(converters));

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

            return(commandOption);
        }
        internal static CommandOption Create(PropertyInfo propertyInfo, CommandMetadata commandMetadata, IEnumerable<IConverter> converters)
        {
            Guard.NotNull(propertyInfo, nameof(propertyInfo));
            Guard.NotNull(commandMetadata, nameof(commandMetadata));
            Guard.NotNull(converters, nameof(converters));

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