/// <summary>
        /// Deserialize the given <see cref="ReadOnlySpan{char}"/> into the given primitive type
        /// </summary>
        public static object Deserialize(ref ReadOnlySpan <char> content, Type primitiveType)
        {
            string value = StringDeserializer.Deserialize(ref content);

            if (!converters.TryGetValue(primitiveType, out TypeConverter converter))
            {
                converter = TypeDescriptor.GetConverter(primitiveType);
                converters.Add(primitiveType, converter);
            }

            return(converter.ConvertFromString(value));
        }
示例#2
0
        public static object Deserialize(JsonObjectType type, ref ReadOnlySpan <char> content, Type resultType)
        {
            switch (type)
            {
            case JsonObjectType.Array:
                return(CollectionDeserializer.Deserialize(ref content, resultType));

            case JsonObjectType.Object:
                return(ObjectDeserializer.Deserialize(ref content, resultType));

            case JsonObjectType.Primitive:
                return(PrimitiveDeserializer.Deserialize(ref content, resultType));

            case JsonObjectType.String:
                return(StringDeserializer.Deserialize(ref content));

            default:
                throw new ArgumentException(nameof(type));
            }
        }