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


C# JsonArrayContract.InvokeOnDeserializing方法代码示例

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


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

示例1: PopulateList

    private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, string reference, JsonArrayContract contract)
    {
      object list = wrappedList.UnderlyingCollection;

      // can't populate an existing array
      if (wrappedList.IsFixedSize)
      {
        reader.Skip();
        return wrappedList.UnderlyingCollection;
      }

      if (reference != null)
        Serializer.ReferenceResolver.AddReference(this, reference, list);

      contract.InvokeOnDeserializing(list, Serializer.Context);

      int initialDepth = reader.Depth;
      int index = 0;

      JsonContract collectionItemContract = GetContractSafe(contract.CollectionItemType);
      JsonConverter collectionItemConverter = GetConverter(collectionItemContract, null);

      while (true)
      {
        try
        {
          if (ReadForType(reader, collectionItemContract, collectionItemConverter != null, true))
          {
            switch (reader.TokenType)
            {
              case JsonToken.EndArray:
                contract.InvokeOnDeserialized(list, Serializer.Context);

                return wrappedList.UnderlyingCollection;
              case JsonToken.Comment:
                break;
              default:
                object value = CreateValueNonProperty(reader, contract.CollectionItemType, collectionItemContract, collectionItemConverter);

                wrappedList.Add(value);
                break;
            }
          }
          else
          {
            break;
          }
        }
        catch (Exception ex)
        {
          if (IsErrorHandled(list, contract, index, reader.Path, ex))
            HandleError(reader, initialDepth);
          else
            throw;
        }
        finally
        {
          index++;
        }
      }

      throw CreateSerializationException(reader, "Unexpected end when deserializing array.");
    }
开发者ID:bladefist,项目名称:Newtonsoft.Json,代码行数:63,代码来源:JsonSerializerInternalReader.cs

示例2: 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

示例3: PopulateList

    private object PopulateList(IWrappedCollection wrappedList, JsonReader reader, string reference, JsonArrayContract contract)
    {
      object list = wrappedList.UnderlyingCollection;

      if (reference != null)
        Serializer.ReferenceResolver.AddReference(reference, list);

      contract.InvokeOnDeserializing(list, Serializer.Context);

      int initialDepth = reader.Depth;

      while (reader.Read())
      {
        switch (reader.TokenType)
        {
          case JsonToken.EndArray:
            contract.InvokeOnDeserialized(list, Serializer.Context);

            return wrappedList.UnderlyingCollection;
          case JsonToken.Comment:
            break;
          default:
            try
            {
              object value = CreateValueNonProperty(reader, contract.CollectionItemType, GetContractSafe(contract.CollectionItemType));

              wrappedList.Add(value);
            }
            catch (Exception ex)
            {
              if (IsErrorHandled(list, contract, wrappedList.Count, ex))
                HandleError(reader, initialDepth);
              else
                throw;
            }
            break;
        }
      }

      throw new JsonSerializationException("Unexpected end when deserializing array.");
    }
开发者ID:nathanpalmer,项目名称:ravendb,代码行数:41,代码来源:JsonSerializerInternalReader.cs

示例4: PopulateMultidimensionalArray

    private object PopulateMultidimensionalArray(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, string id)
    {
      int rank = contract.UnderlyingType.GetArrayRank();

      if (id != null)
        Serializer.ReferenceResolver.AddReference(this, id, list);

      contract.InvokeOnDeserializing(list, Serializer.Context);

      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;

      while (true)
      {
        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 = collectionItemConverter.ReadJson(reader, contract.CollectionItemType, null, GetInternalSerializer());
                  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.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
                {
                  contract.InvokeOnDeserialized(list, Serializer.Context);
//.........这里部分代码省略.........
开发者ID:Contatta,项目名称:Newtonsoft.Json,代码行数:101,代码来源:JsonSerializerInternalReader.cs

示例5: PopulateMultidimensionalArray

		private object PopulateMultidimensionalArray(IList list, JsonReader reader, string reference, JsonArrayContract contract)
		{
			int rank = contract.UnderlyingType.GetArrayRank();

			if (reference != null)
				Serializer.ReferenceResolver.AddReference(this, reference, list);

			contract.InvokeOnDeserializing(list, Serializer.Context);

			//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)
				{
					if (ReadForTypeArrayHack(reader, contract.CollectionItemType))
					{
						switch (reader.TokenType)
						{
							case JsonToken.EndArray:
								listStack.Pop();
								currentList = listStack.Peek();
								//previousErrorIndex = null;
								break;
							case JsonToken.Comment:
								break;
							default:
								try
								{
									object value = CreateValueNonProperty(reader, contract.CollectionItemType, GetContractSafe(contract.CollectionItemType));

									currentList.Add(value);
								}
								catch (Exception ex)
								{
									if (IsErrorHandled(list, contract, currentList.Count, ex))
										HandleError(reader, initialDepth);
									else
										throw;
								}
								break;
						}
					}
					else
					{
						break;
					}


				}
				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
								{
									finished = true;
								}
								break;
							case JsonToken.Comment:
								break;
							default:
								throw new JsonSerializationException("Unexpected token when deserializing multidimensional array: " + reader.TokenType);
						}
					}
					else
					{
						break;
					}
				}
			} while (!finished);

			if (!finished)
				throw new JsonSerializationException("Unexpected end when deserializing array." + reader.TokenType);

			contract.InvokeOnDeserialized(list, Serializer.Context);
//.........这里部分代码省略.........
开发者ID:GregLukosek,项目名称:Crowd,代码行数:101,代码来源:JsonSerializerInternalReader.cs

示例6: 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

示例7: 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

示例8: PopulateList

        private IList PopulateList(IList list, JsonReader reader, string reference, JsonArrayContract contract)
        {
            if (reference != null)
            _serializer.ReferenceResolver.AddReference(reference, list);

              contract.InvokeOnDeserializing(list);

              while (reader.Read())
              {
            switch (reader.TokenType)
            {
              case JsonToken.EndArray:
            contract.InvokeOnDeserialized(list);

            return list;
              case JsonToken.Comment:
            break;
              default:
            object value = CreateValue(reader, contract.CollectionItemType, null, null);

            list.Add(value);
            break;
            }
              }

              throw new JsonSerializationException("Unexpected end when deserializing array.");
        }
开发者ID:BGCX262,项目名称:zulu-omoto-pos-client-svn-to-git,代码行数:27,代码来源:JsonSerializerReader.cs


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