本文整理汇总了C#中Newtonsoft.Json.JsonReader.GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.GetPosition方法的具体用法?C# JsonReader.GetPosition怎么用?C# JsonReader.GetPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.JsonReader
的用法示例。
在下文中一共展示了JsonReader.GetPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PopulateList
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;
}
}
示例2: PopulateMultidimensionalArray
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;
}