Пример #1
0
        private object PopulateMultidimensionalArray(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
        {
            int rank = contract.UnderlyingType.GetArrayRank();

              if (id != null)
            AddReference(reader, id, list);

              OnDeserializing(reader, contract, list);

              JsonContract collectionItemContract = GetContractSafe(contract.CollectionItemType);
              JsonConverter collectionItemConverter = GetConverter(collectionItemContract, null, contract, containerProperty);

              int? previousErrorIndex = null;
              Stack<IList> listStack = new Stack<IList>();
              listStack.Push(list);
              IList currentList = list;

              bool finished = false;
              do
              {
            int initialDepth = reader.Depth;

            if (listStack.Count == rank)
            {
              try
              {
            if (ReadForType(reader, collectionItemContract, collectionItemConverter != null))
            {
              switch (reader.TokenType)
              {
                case JsonToken.EndArray:
                  listStack.Pop();
                  currentList = listStack.Peek();
                  previousErrorIndex = null;
                  break;
                case JsonToken.Comment:
                  break;
                default:
                  object value;

                  if (collectionItemConverter != null && collectionItemConverter.CanRead)
                    value = DeserializeConvertable(collectionItemConverter, reader, contract.CollectionItemType, null);
                  else
                    value = CreateValueInternal(reader, contract.CollectionItemType, collectionItemContract, null, contract, containerProperty, null);

                  currentList.Add(value);
                  break;
              }
            }
            else
            {
              break;
            }
              }
              catch (Exception ex)
              {
            JsonPosition errorPosition = reader.GetPosition(initialDepth);

            if (IsErrorHandled(list, contract, errorPosition.Position, reader as IJsonLineInfo, reader.Path, ex))
            {
              HandleError(reader, true, initialDepth);

              if (previousErrorIndex != null && previousErrorIndex == errorPosition.Position)
              {
                // reader index has not moved since previous error handling
                // break out of reading array to prevent infinite loop
                throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex);
              }
              else
              {
                previousErrorIndex = errorPosition.Position;
              }
            }
            else
            {
              throw;
            }
              }
            }
            else
            {
              if (reader.Read())
              {
            switch (reader.TokenType)
            {
              case JsonToken.StartArray:
                IList newList = new List<object>();
                currentList.Add(newList);
                listStack.Push(newList);
                currentList = newList;
                break;
              case JsonToken.EndArray:
                listStack.Pop();

                if (listStack.Count > 0)
                {
                  currentList = listStack.Peek();
                }
                else
                {
                  finished = true;
                }
                break;
              case JsonToken.Comment:
                break;
              default:
                throw JsonSerializationException.Create(reader, "Unexpected token when deserializing multidimensional array: " + reader.TokenType);
            }
              }
              else
              {
            break;
              }
            }
              } while (!finished);

              if (!finished)
            ThrowUnexpectedEndException(reader, contract, list, "Unexpected end when deserializing array.");

              OnDeserialized(reader, contract, list);
              return list;
        }
Пример #2
0
        private object PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
        {
            IWrappedCollection wrappedCollection = list as IWrappedCollection;
              object underlyingList = wrappedCollection != null ? wrappedCollection.UnderlyingCollection : list;

              if (id != null)
            AddReference(reader, id, underlyingList);

              // can't populate an existing array
              if (list.IsFixedSize)
              {
            reader.Skip();
            return underlyingList;
              }

              OnDeserializing(reader, contract, underlyingList);

              int initialDepth = reader.Depth;

              if (contract.ItemContract == null)
            contract.ItemContract = GetContractSafe(contract.CollectionItemType);

              JsonConverter collectionItemConverter = GetConverter(contract.ItemContract, null, contract, containerProperty);

              int? previousErrorIndex = null;

              bool finished = false;
              do
              {
            try
            {
              if (ReadForType(reader, contract.ItemContract, collectionItemConverter != null))
              {
            switch (reader.TokenType)
            {
              case JsonToken.EndArray:
                finished = true;
                break;
              case JsonToken.Comment:
                break;
              default:
                object value;

                if (collectionItemConverter != null && collectionItemConverter.CanRead)
                  value = DeserializeConvertable(collectionItemConverter, reader, contract.CollectionItemType, null);
                else
                  value = CreateValueInternal(reader, contract.CollectionItemType, contract.ItemContract, null, contract, containerProperty, null);

                list.Add(value);
                break;
            }
              }
              else
              {
            break;
              }
            }
            catch (Exception ex)
            {
              JsonPosition errorPosition = reader.GetPosition(initialDepth);

              if (IsErrorHandled(underlyingList, contract, errorPosition.Position, reader as IJsonLineInfo, reader.Path, ex))
              {
            HandleError(reader, true, initialDepth);

            if (previousErrorIndex != null && previousErrorIndex == errorPosition.Position)
            {
              // reader index has not moved since previous error handling
              // break out of reading array to prevent infinite loop
              throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex);
            }
            else
            {
              previousErrorIndex = errorPosition.Position;
            }
              }
              else
              {
            throw;
              }
            }
              } while (!finished);

              if (!finished)
            ThrowUnexpectedEndException(reader, contract, underlyingList, "Unexpected end when deserializing array.");

              OnDeserialized(reader, contract, underlyingList);
              return underlyingList;
        }
 // Token: 0x06000BD2 RID: 3026
 // RVA: 0x000450F0 File Offset: 0x000432F0
 private object PopulateMultidimensionalArray(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
 {
     int arrayRank = contract.UnderlyingType.GetArrayRank();
     if (id != null)
     {
         this.AddReference(reader, id, list);
     }
     this.OnDeserializing(reader, contract, list);
     JsonContract contractSafe = this.GetContractSafe(contract.CollectionItemType);
     JsonConverter converter = this.GetConverter(contractSafe, null, contract, containerProperty);
     int? num = null;
     Stack<IList> stack = new Stack<IList>();
     stack.Push(list);
     IList list2 = list;
     bool flag = false;
     while (true)
     {
         int depth = reader.Depth;
         if (stack.Count == arrayRank)
         {
             try
             {
                 if (!this.ReadForType(reader, contractSafe, converter != null))
                 {
                     goto IL_214;
                 }
                 JsonToken tokenType = reader.TokenType;
                 if (tokenType != JsonToken.Comment)
                 {
                     if (tokenType == JsonToken.EndArray)
                     {
                         stack.Pop();
                         list2 = stack.Peek();
                         num = null;
                     }
                     else
                     {
                         object value;
                         if (converter != null && converter.CanRead)
                         {
                             value = this.DeserializeConvertable(converter, reader, contract.CollectionItemType, null);
                         }
                         else
                         {
                             value = this.CreateValueInternal(reader, contract.CollectionItemType, contractSafe, null, contract, containerProperty, null);
                         }
                         list2.Add(value);
                     }
                 }
             }
             catch (Exception ex)
             {
                 JsonPosition position = reader.GetPosition(depth);
                 if (!base.IsErrorHandled(list, contract, position.Position, reader as IJsonLineInfo, reader.Path, ex))
                 {
                     throw;
                 }
                 this.HandleError(reader, true, depth);
                 if (num.HasValue && num == position.Position)
                 {
                     throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex);
                 }
                 num = new int?(position.Position);
             }
         }
         else
         {
             if (!reader.Read())
             {
                 goto IL_214;
             }
             JsonToken tokenType2 = reader.TokenType;
             if (tokenType2 != JsonToken.StartArray)
             {
                 if (tokenType2 != JsonToken.Comment)
                 {
                     if (tokenType2 != JsonToken.EndArray)
                     {
                         break;
                     }
                     stack.Pop();
                     if (stack.Count > 0)
                     {
                         list2 = stack.Peek();
                     }
                     else
                     {
                         flag = true;
                     }
                 }
             }
             else
             {
                 IList list3 = new List<object>();
                 list2.Add(list3);
                 stack.Push(list3);
                 list2 = list3;
             }
         }
         if (flag)
         {
             goto Block_9;
         }
     }
     throw JsonSerializationException.Create(reader, "Unexpected token when deserializing multidimensional array: " + reader.TokenType);
     Block_9:
     IL_214:
     if (!flag)
     {
         this.ThrowUnexpectedEndException(reader, contract, list, "Unexpected end when deserializing array.");
     }
     this.OnDeserialized(reader, contract, list);
     return list;
 }
    private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
    {
      object list = wrappedList.UnderlyingCollection;

      if (id != null)
        Serializer.ReferenceResolver.AddReference(this, id, list);

      // can't populate an existing array
      if (wrappedList.IsFixedSize)
      {
        reader.Skip();
        return list;
      }

      contract.InvokeOnDeserializing(list, Serializer.Context);

      int initialDepth = reader.Depth;

      JsonContract collectionItemContract = GetContractSafe(contract.CollectionItemType);
      JsonConverter collectionItemConverter = GetConverter(collectionItemContract, null, contract, containerProperty);

      int? previousErrorIndex = null;

      while (true)
      {
        try
        {
          if (ReadForType(reader, collectionItemContract, collectionItemConverter != null))
          {
            switch (reader.TokenType)
            {
              case JsonToken.EndArray:
                contract.InvokeOnDeserialized(list, Serializer.Context);

                return list;
              case JsonToken.Comment:
                break;
              default:
                object value;

                if (collectionItemConverter != null && collectionItemConverter.CanRead)
                  value = collectionItemConverter.ReadJson(reader, contract.CollectionItemType, null, GetInternalSerializer());
                else
                  value = CreateValueInternal(reader, contract.CollectionItemType, collectionItemContract, null, contract, containerProperty, null);

                wrappedList.Add(value);
                break;
            }
          }
          else
          {
            break;
          }
        }
        catch (Exception ex)
        {
          JsonPosition errorPosition = reader.GetPosition(initialDepth);

          if (IsErrorHandled(list, contract, errorPosition.Position, reader.Path, ex))
          {
            HandleError(reader, true, initialDepth);

            if (previousErrorIndex != null && previousErrorIndex == errorPosition.Position)
            {
              // reader index has not moved since previous error handling
              // break out of reading array to prevent infinite loop
              throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex);
            }
            else
            {
              previousErrorIndex = errorPosition.Position;
            }
          }
          else
          {
            throw;
          }
        }
      }

      throw JsonSerializationException.Create(reader, "Unexpected end when deserializing array.");
    }
 // Token: 0x06000BD4 RID: 3028
 // RVA: 0x0004538C File Offset: 0x0004358C
 private object PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
 {
     IWrappedCollection wrappedCollection = list as IWrappedCollection;
     object obj = (wrappedCollection != null) ? wrappedCollection.UnderlyingCollection : list;
     if (id != null)
     {
         this.AddReference(reader, id, obj);
     }
     if (list.IsFixedSize)
     {
         reader.Skip();
         return obj;
     }
     this.OnDeserializing(reader, contract, obj);
     int depth = reader.Depth;
     if (contract.ItemContract == null)
     {
         contract.ItemContract = this.GetContractSafe(contract.CollectionItemType);
     }
     JsonConverter converter = this.GetConverter(contract.ItemContract, null, contract, containerProperty);
     int? num = null;
     bool flag = false;
     do
     {
         try
         {
             if (!this.ReadForType(reader, contract.ItemContract, converter != null))
             {
                 break;
             }
             JsonToken tokenType = reader.TokenType;
             if (tokenType != JsonToken.Comment)
             {
                 if (tokenType == JsonToken.EndArray)
                 {
                     flag = true;
                 }
                 else
                 {
                     object value;
                     if (converter != null && converter.CanRead)
                     {
                         value = this.DeserializeConvertable(converter, reader, contract.CollectionItemType, null);
                     }
                     else
                     {
                         value = this.CreateValueInternal(reader, contract.CollectionItemType, contract.ItemContract, null, contract, containerProperty, null);
                     }
                     list.Add(value);
                 }
             }
         }
         catch (Exception ex)
         {
             JsonPosition position = reader.GetPosition(depth);
             if (!base.IsErrorHandled(obj, contract, position.Position, reader as IJsonLineInfo, reader.Path, ex))
             {
                 throw;
             }
             this.HandleError(reader, true, depth);
             if (num.HasValue && num == position.Position)
             {
                 throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex);
             }
             num = new int?(position.Position);
         }
     }
     while (!flag);
     if (!flag)
     {
         this.ThrowUnexpectedEndException(reader, contract, obj, "Unexpected end when deserializing array.");
     }
     this.OnDeserialized(reader, contract, obj);
     return obj;
 }