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;
}
}