コード例 #1
0
        public IValueParser GetParserForProperty(OptionPropertyMetadata optionProperty)
        {
            if (optionProperty.HasCustomParser)
            {
                return(CreateExternalParser(optionProperty.CustomParserType));
            }

            return(DefaultParsers.GetValueParser(optionProperty.ParsedType));
        }
コード例 #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);
        }