internal object Deserialize(Type nativeType)
        {
            if (nativeType == null)
            {
                throw Error.ArgumentNull(nameof(nativeType));
            }

            object primitiveValue = _current.GetPrimitiveValue();

            if (nativeType.IsEnum() && primitiveValue.GetType() == typeof(string))
            {
                // Don't try to parse enums in the parser -> it's been moved to the Code<T> type
                return(primitiveValue);
            }

            try
            {
                return(PrimitiveTypeConverter.ConvertTo(primitiveValue, nativeType));
            }
            catch (NotSupportedException exc)
            {
                // thrown when an unsupported conversion was required
                throw Error.Format(exc.Message, _current);
            }
        }
        internal object Deserialize(Type nativeType)
        {
            if (nativeType == null)
            {
                throw Error.ArgumentNull("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.ConvertTo(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);
            }
        }