Ejemplo n.º 1
0
        public IValueParser GetParserForProperty(OptionPropertyMetadata optionProperty)
        {
            if (optionProperty.HasCustomParser)
            {
                return(CreateExternalParser(optionProperty.CustomParserType));
            }

            return(DefaultParsers.GetValueParser(optionProperty.ParsedType));
        }
Ejemplo n.º 2
0
        private bool TryParseUnderlyingTypeValue(string rawValue, Type targetType, out object parsedValue)
        {
            var underlyingType       = targetType.GetEnumUnderlyingType();
            var underlyingTypeParser = DefaultParsers.GetValueParser(underlyingType);

            try
            {
                var numericValue = underlyingTypeParser.Parse(rawValue, targetType);

                if (Enum.IsDefined(targetType, numericValue))
                {
                    parsedValue = Enum.ToObject(targetType, numericValue);
                    return(true);
                }
            }
            catch (Exception)
            {
                // Ignore
            }

            parsedValue = null;
            return(false);
        }
Ejemplo n.º 3
0
 public bool HasParserForProperty(OptionPropertyMetadata propertyMetadata)
 {
     return(propertyMetadata.HasCustomParser ||
            propertyMetadata.IsCollection ||
            DefaultParsers.HasParser(propertyMetadata.ParsedType));
 }