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


C# JsonReader.GetPosition方法代码示例

本文整理汇总了C#中JsonReader.GetPosition方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.GetPosition方法的具体用法?C# JsonReader.GetPosition怎么用?C# JsonReader.GetPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonReader的用法示例。


在下文中一共展示了JsonReader.GetPosition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PopulateMultidimensionalArray

        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
                {
//.........这里部分代码省略.........
开发者ID:rv192,项目名称:Fussen,代码行数:101,代码来源:JsonSerializerInternalReader.cs

示例2: PopulateList

        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;
        }
开发者ID:rv192,项目名称:Fussen,代码行数:89,代码来源:JsonSerializerInternalReader.cs

示例3: PopulateMultidimensionalArray

 // 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;
             }
//.........这里部分代码省略.........
开发者ID:newchild,项目名称:Project-DayZero,代码行数:101,代码来源:JsonSerializerInternalReader.cs

示例4: PopulateList

    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.");
    }
开发者ID:Contatta,项目名称:Newtonsoft.Json,代码行数:82,代码来源:JsonSerializerInternalReader.cs

示例5: PopulateList

 // 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;
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:77,代码来源:JsonSerializerInternalReader.cs


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