public void DefaultStringConverterActivation()
            {
                // Arrange
                var expected = typeof (Int32Converter);
                var converterAttribute = new ConverterKeyValueAttribute(expected);

                // Act
                var actual = converterAttribute.BuildValueConverter();

                // Assert
                Assert.NotNull(actual);
                Assert.IsType<Int32Converter>(actual);
            }
            public void Int32ConverterActivation()
            {
                // Arrange
                var expected = typeof (Int32Converter);
                var valueConverterType = typeof (GuidConverter);
                var converterAttribute = new ConverterKeyValueAttribute(valueConverterType, expected);

                // Act
                var actual = converterAttribute.BuildKeyConverter();

                // Assert
                Assert.NotNull(actual);
                Assert.IsType<Int32Converter>(actual);
            }
示例#3
0
        internal static IConverter BuildValueConverter(this ConverterKeyValueAttribute source)
        {
            Guard.NotNull(source, nameof(source));

            return(Activator.CreateInstance(source.ValueConverterType) as IConverter);
        }
        private static IConverter GetKeyConverter(PropertyInfo propertyInfo, string optionName, string commandName, ConverterKeyValueAttribute converterKeyValuePairAttribute)
        {
            var keyType = propertyInfo.PropertyType.GetUnderlyingDictionaryType(true);
            var keyConverter = converterKeyValuePairAttribute.BuildKeyConverter();
            if (!keyType.IsAssignableFrom(keyConverter.TargetType))
            {
                throw new CommandLineParserException(Constants.ExceptionMessages.ParserExtractKeyConverterIsNotValid(optionName, commandName, keyType, keyConverter.TargetType));
            }

            return keyConverter;
        }