当前位置: 首页>>代码示例>>C#>>正文


C# JsonReader.GetPosition方法代码示例

本文整理汇总了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;
   }
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:66,代码来源:JsonSerializerInternalReader.cs

示例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;
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:96,代码来源:JsonSerializerInternalReader.cs


注:本文中的Newtonsoft.Json.JsonReader.GetPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。