private object read(Type nativeType) { object primitiveValue = _current.GetPrimitiveValue(); if (nativeType.IsEnum() && primitiveValue.GetType() == typeof(string)) { var enumMapping = _inspector.FindEnumMappingByType(nativeType); if (enumMapping != null) { var enumLiteral = (string)primitiveValue; if (enumMapping.ContainsLiteral(enumLiteral)) { return(enumMapping.ParseLiteral((string)primitiveValue)); } else { throw Error.Format("Literal {0} is not a valid value for enumeration {1}", _current, enumLiteral, enumMapping.Name); } } else { throw Error.Format("Cannot find an enumeration mapping for enum " + nativeType.Name, _current); } } try { return(PrimitiveTypeConverter.Convert(primitiveValue, nativeType)); } catch (NotSupportedException exc) { // thrown when an unsupported conversion was required throw Error.Format(exc.Message, _current); } }
private object read(Type nativeType) { object primitiveValue = _current.GetPrimitiveValue(); if (nativeType.IsEnum && primitiveValue.GetType() == typeof(string)) { var enumMapping = _inspector.FindEnumMappingByType(nativeType); if (enumMapping != null) { return(enumMapping.ParseLiteral((string)primitiveValue)); } } try { return(PrimitiveTypeConverter.Convert(primitiveValue, nativeType)); } catch (NotSupportedException exc) { // thrown when an unsupported conversion was required throw Error.Format(exc.Message, _current); } }