/// <summary>
        /// deserialize json
        /// </summary>
        /// <param name="typeGo"></param>
        /// <param name="instance"></param>
        /// <param name="json">json value</param>
        /// <param name="createInstance">index of start string</param>
        /// <returns>value deserialized</returns>
        internal static ReadOnlySpan <char> Extract(JsonDeserializer deserializer, TypeGoInfo typeGo, ref object instance, Func <object> createInstance, ref JsonSpanReader json)
        {
            var character = json.Read();

            if (character == JsonConstantsBytes.Quotes)
            {
                //if (typeGo.IsNoQuotesValueType)
                return(json.ExtractString());
                //else
                //    return json.ExtractStringQuotes();
            }
            else if (character == JsonConstantsBytes.OpenBraket)
            {
                //if (createInstance != null)
                //    instance = createInstance();
                ExtractOject(deserializer, typeGo, ref instance, ref json);
            }
            else if (character == JsonConstantsBytes.OpenSquareBrackets)
            {
                if (instance == null && typeGo.CreateInstance != null)
                {
                    instance = typeGo.CreateInstance();
                }
                ExtractArray(deserializer, typeGo, ref instance, ref json);
            }
            else
            {
                if (createInstance != null)
                {
                    instance = null;
                }
                return(json.ExtractValue());
            }
            return(null);
        }
        static void ExtractArray(JsonDeserializer deserializer, TypeGoInfo typeGo, ref object instance, ref JsonSpanReader json)
        {
            var generic = typeGo.Generics.First();

            while (true)
            {
                var character = json.Read();
                if (character == JsonConstantsBytes.OpenBraket)
                {
                    object genericInstance = null;
                    ExtractOject(deserializer, generic, ref genericInstance, ref json);
                    typeGo.AddArrayValue(instance, genericInstance);
                }
                else if (character == JsonConstantsBytes.OpenSquareBrackets)
                {
                    object genericInstance = null;
                    ExtractArray(deserializer, generic, ref genericInstance, ref json);
                    typeGo.AddArrayValue(instance, genericInstance);
                }
                else if (character == JsonConstantsBytes.Comma)
                {
                    continue;
                }
                else if (character == JsonConstantsBytes.CloseSquareBrackets)
                {
                    break;
                }
                else if (character == JsonConstantsBytes.Quotes)
                {
                    var value = json.ExtractString();
                    typeGo.AddArrayValue(instance, generic.JsonDeserialize(deserializer, value));
                }
                else
                {
                    var value = json.ExtractValue();
                    if (generic.JsonDeserialize != null)
                    {
                        typeGo.AddArrayValue(instance, generic.JsonDeserialize(deserializer, value));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        //internal override void InternalSetValue(ref TObject instance, ref object value)
        //{
        //    SetValue(instance, (TPropertyType)value);
        //}

        internal override void JsonDeserializeString(ref TObject instance, ref JsonSpanReader reader)
        {
            ReadOnlySpan<char> extract = reader.ExtractString();
            SetValue(instance, TypeGoInfo.JsonDeserialize(ref extract));
        }