Esempio n. 1
0
        private object InternalReadJson(JsonReader reader, JsonSerializer serializer, bool isNullableStruct)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(CreateValueForNull(isNullableStruct));
            }

            if (reader.TokenType != JsonToken.StartObject)
            {
                throw reader.CreateSerializationException($"Failed to read type '{typeof(T).Name}'. Expected object start, got '{reader.TokenType}' <{reader.Value}>");
            }

            reader.Read();

            var values        = new ValuesArray <TInner>(_namesArray.Length);
            int previousIndex = -1;

            while (reader.TokenType == JsonToken.PropertyName)
            {
                if (reader.Value is string name &&
                    _namesIndices.TryGetValue(name, out int index))
                {
                    if (index == previousIndex)
                    {
                        throw reader.CreateSerializationException($"Failed to read type '{typeof(T).Name}'. Possible loop when reading property '{name}'");
                    }

                    previousIndex = index;
                    values[index] = ReadValue(reader, index, serializer);
                }
Esempio n. 2
0
 /// <summary>
 /// Create the instance with the given values.
 /// </summary>
 /// <param name="values">The values read from the object. Known to have the same size as number of elements fed through the constructor of this PartialConverter.</param>
 /// <returns>The instance.</returns>
 protected abstract T CreateInstanceFromValues(ValuesArray <TInner> values);