private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id) { object underlyingCollection = wrappedList.UnderlyingCollection; if (id != null) this.AddReference(reader, id, underlyingCollection); if (wrappedList.IsFixedSize) { reader.Skip(); return underlyingCollection; } else { contract.InvokeOnDeserializing(underlyingCollection, this.Serializer.Context); int depth = reader.Depth; JsonContract contractSafe = this.GetContractSafe(contract.CollectionItemType); JsonConverter converter = this.GetConverter(contractSafe, (JsonConverter) null, (JsonContainerContract) contract, containerProperty); int? nullable1 = new int?(); bool flag = false; do { try { if (this.ReadForType(reader, contractSafe, converter != null)) { switch (reader.TokenType) { case JsonToken.Comment: break; case JsonToken.EndArray: flag = true; break; default: object obj = converter == null || !converter.CanRead ? this.CreateValueInternal(reader, contract.CollectionItemType, contractSafe, (JsonProperty) null, (JsonContainerContract) contract, containerProperty, (object) null) : converter.ReadJson(reader, contract.CollectionItemType, (object) null, (JsonSerializer) this.GetInternalSerializer()); wrappedList.Add(obj); break; } } else break; } catch (Exception ex) { JsonPosition position = reader.GetPosition(depth); if (this.IsErrorHandled(underlyingCollection, (JsonContract) contract, (object) position.Position, reader.Path, ex)) { this.HandleError(reader, true, depth); if (nullable1.HasValue) { int? nullable2 = nullable1; int? nullable3 = position.Position; if ((nullable2.GetValueOrDefault() != nullable3.GetValueOrDefault() ? 0 : (nullable2.HasValue == nullable3.HasValue ? 1 : 0)) != 0) throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex); } nullable1 = position.Position; } else throw; } } while (!flag); if (!flag) this.ThrowUnexpectedEndException(reader, (JsonContract) contract, underlyingCollection, "Unexpected end when deserializing array."); contract.InvokeOnDeserialized(underlyingCollection, this.Serializer.Context); return underlyingCollection; } }
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, (object) list); contract.InvokeOnDeserializing((object) list, this.Serializer.Context); JsonContract contractSafe = this.GetContractSafe(contract.CollectionItemType); JsonConverter converter = this.GetConverter(contractSafe, (JsonConverter) null, (JsonContainerContract) contract, containerProperty); int? nullable1 = new int?(); Stack<IList> stack = new Stack<IList>(); stack.Push(list); IList list1 = list; bool flag = false; do { int depth = reader.Depth; if (stack.Count == arrayRank) { try { if (this.ReadForType(reader, contractSafe, converter != null)) { switch (reader.TokenType) { case JsonToken.Comment: break; case JsonToken.EndArray: stack.Pop(); list1 = stack.Peek(); nullable1 = new int?(); break; default: object obj = converter == null || !converter.CanRead ? this.CreateValueInternal(reader, contract.CollectionItemType, contractSafe, (JsonProperty) null, (JsonContainerContract) contract, containerProperty, (object) null) : converter.ReadJson(reader, contract.CollectionItemType, (object) null, (JsonSerializer) this.GetInternalSerializer()); list1.Add(obj); break; } } else break; } catch (Exception ex) { JsonPosition position = reader.GetPosition(depth); if (this.IsErrorHandled((object) list, (JsonContract) contract, (object) position.Position, reader.Path, ex)) { this.HandleError(reader, true, depth); if (nullable1.HasValue) { int? nullable2 = nullable1; int? nullable3 = position.Position; if ((nullable2.GetValueOrDefault() != nullable3.GetValueOrDefault() ? 0 : (nullable2.HasValue == nullable3.HasValue ? 1 : 0)) != 0) throw JsonSerializationException.Create(reader, "Infinite loop detected from error handling.", ex); } nullable1 = position.Position; } else throw; } } else if (reader.Read()) { switch (reader.TokenType) { case JsonToken.StartArray: IList list2 = (IList) new List<object>(); list1.Add((object) list2); stack.Push(list2); list1 = list2; break; case JsonToken.Comment: break; case JsonToken.EndArray: stack.Pop(); if (stack.Count > 0) { list1 = stack.Peek(); break; } else { flag = true; break; } default: throw JsonSerializationException.Create(reader, "Unexpected token when deserializing multidimensional array: " + (object) reader.TokenType); } } else break; } while (!flag); if (!flag) this.ThrowUnexpectedEndException(reader, (JsonContract) contract, (object) list, "Unexpected end when deserializing array."); contract.InvokeOnDeserialized((object) list, this.Serializer.Context); return (object) list; }