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


C# JsonArrayContract.InvokeOnSerialized方法代码示例

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


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

示例1: SerializeMultidimensionalArray

    private void SerializeMultidimensionalArray(JsonWriter writer, Array values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
    {
      contract.InvokeOnSerializing(values, Serializer.Context);

      _serializeStack.Add(values);

      bool hasWrittenMetadataObject = WriteStartArray(writer, values, contract, member, collectionContract, containerProperty);

      SerializeMultidimensionalArray(writer, values, contract, member, writer.Top, new int[0]);

      if (hasWrittenMetadataObject)
        writer.WriteEndObject();

      _serializeStack.RemoveAt(_serializeStack.Count - 1);

      contract.InvokeOnSerialized(values, Serializer.Context);
    }
开发者ID:draptik,项目名称:RepoSync,代码行数:17,代码来源:JsonSerializerInternalWriter.cs

示例2: SerializeList


//.........这里部分代码省略.........
				writer.WriteStartObject();

				if (isReference)
				{
					writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
					writer.WriteValue(Serializer.ReferenceResolver.GetReference(this, values.UnderlyingCollection));
				}
				if (includeTypeDetails)
				{
					WriteTypeProperty(writer, values.UnderlyingCollection.GetType());
				}
				writer.WritePropertyName(JsonTypeReflector.ArrayValuesPropertyName);
			}

			JsonContract childValuesContract = Serializer.ContractResolver.ResolveContract(contract.CollectionItemType ?? typeof(object));

			writer.WriteStartArray();

			int initialDepth = writer.Top;

			int index = 0;
			// note that an error in the IEnumerable won't be caught
#if !(UNITY_IPHONE || UNITY_IOS)
			foreach (object value in values)
			{
				try
				{
					JsonContract valueContract = GetContractSafe(value);

					if (ShouldWriteReference(value, null, valueContract))
					{
						WriteReference(writer, value);
					}
					else
					{
						if (CheckForCircularReference(value, null, contract))
						{
							SerializeValue(writer, value, valueContract, null, childValuesContract);
						}
					}
				}
				catch (Exception ex)
				{
					if (IsErrorHandled(values.UnderlyingCollection, contract, index, ex))
						HandleError(writer, initialDepth);
					else
						throw;
				}
				finally
				{
					index++;
				}
			}
#else

			values.ForEach(value =>
			{
				try
				{
					JsonContract valueContract = GetContractSafe(value);

					if (ShouldWriteReference(value, null, valueContract))
					{
						WriteReference(writer, value);
					}
					else
					{
						if (CheckForCircularReference(value, null, contract))
						{
							SerializeValue(writer, value, valueContract, null, childValuesContract);
						}
					}
				}
				catch (Exception ex)
				{
					if (IsErrorHandled(values.UnderlyingCollection, contract, index, ex))
						HandleError(writer, initialDepth);
					else
						throw;
				}
				finally
				{
					index++;
				}
			});


#endif

			writer.WriteEndArray();

			if (isReference || includeTypeDetails)
			{
				writer.WriteEndObject();
			}

			SerializeStack.RemoveAt(SerializeStack.Count - 1);

			contract.InvokeOnSerialized(values.UnderlyingCollection, Serializer.Context);
		}
开发者ID:JungWon2,项目名称:memory_book,代码行数:101,代码来源:JsonSerializerInternalWriter.cs

示例3: SerializeList

    private void SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
    {
      contract.InvokeOnSerializing(values.UnderlyingCollection, Serializer.Context);

      _serializeStack.Add(values.UnderlyingCollection);

      bool hasWrittenMetadataObject = WriteStartArray(writer, values.UnderlyingCollection, contract, member, collectionContract, containerProperty);

      writer.WriteStartArray();

      int initialDepth = writer.Top;

      int index = 0;
      // note that an error in the IEnumerable won't be caught
      foreach (object value in values)
      {
        try
        {
          JsonContract valueContract = contract.FinalItemContract ?? GetContractSafe(value);

          if (ShouldWriteReference(value, null, valueContract, contract, member))
          {
            WriteReference(writer, value);
          }
          else
          {
            if (CheckForCircularReference(writer, value, null, valueContract, contract, member))
            {
              SerializeValue(writer, value, valueContract, null, contract, member);
            }
          }
        }
        catch (Exception ex)
        {
          if (IsErrorHandled(values.UnderlyingCollection, contract, index, writer.ContainerPath, ex))
            HandleError(writer, initialDepth);
          else
            throw;
        }
        finally
        {
          index++;
        }
      }

      writer.WriteEndArray();

      if (hasWrittenMetadataObject)
        writer.WriteEndObject();

      _serializeStack.RemoveAt(_serializeStack.Count - 1);

      contract.InvokeOnSerialized(values.UnderlyingCollection, Serializer.Context);
    }
开发者ID:draptik,项目名称:RepoSync,代码行数:54,代码来源:JsonSerializerInternalWriter.cs

示例4: SerializeList

        private void SerializeList(JsonWriter writer, IList values, JsonArrayContract contract, JsonProperty member, JsonContract collectionValueContract)
        {
            contract.InvokeOnSerializing(values, Serializer.Context);

              SerializeStack.Add(values);

              bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Arrays);
              bool includeTypeDetails = ShouldWriteType(TypeNameHandling.Arrays, contract, member, collectionValueContract);

              if (isReference || includeTypeDetails)
              {
            writer.WriteStartObject();

            if (isReference)
            {
              writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
              writer.WriteValue(Serializer.ReferenceResolver.GetReference(values));
            }
            if (includeTypeDetails)
            {
              WriteTypeProperty(writer, values.GetType());
            }
            writer.WritePropertyName(JsonTypeReflector.ArrayValuesPropertyName);
              }

              JsonContract childValuesContract = Serializer.ContractResolver.ResolveContract(contract.CollectionItemType ?? typeof(object));

              writer.WriteStartArray();

              int initialDepth = writer.Top;

              for (int i = 0; i < values.Count; i++)
              {
            try
            {
              object value = values[i];
              JsonContract valueContract = GetContractSafe(value);

              if (ShouldWriteReference(value, null, valueContract))
              {
            WriteReference(writer, value);
              }
              else
              {
            if (!CheckForCircularReference(value, null, contract))
              continue;

            SerializeValue(writer, value, valueContract, null, childValuesContract);
              }
            }
            catch (Exception ex)
            {
              if (IsErrorHandled(values, contract, i, ex))
            HandleError(writer, initialDepth);
              else
            throw;
            }
              }

              writer.WriteEndArray();

              if (isReference || includeTypeDetails)
              {
            writer.WriteEndObject();
              }

              SerializeStack.RemoveAt(SerializeStack.Count - 1);

              contract.InvokeOnSerialized(values, Serializer.Context);
        }
开发者ID:xantilas,项目名称:ghalager-videobrowser-20120129,代码行数:70,代码来源:JsonSerializerInternalWriter.cs

示例5: SerializeList

    private void SerializeList(JsonWriter writer, IList values, JsonArrayContract contract)
    {
      contract.InvokeOnSerializing(values);

      SerializeStack.Add(values);

      bool isReference = contract.IsReference ?? HasFlag(_serializer.PreserveReferencesHandling, PreserveReferencesHandling.Arrays);
      bool includeTypeDetails = HasFlag(_serializer.TypeNameHandling, TypeNameHandling.Arrays);

      if (isReference || includeTypeDetails)
      {
        writer.WriteStartObject();

        if (isReference)
        {
          writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
          writer.WriteValue(_serializer.ReferenceResolver.GetReference(values));
        }
        if (includeTypeDetails)
        {
          WriteTypeProperty(writer, values.GetType());
        }
        writer.WritePropertyName(JsonTypeReflector.ArrayValuesPropertyName);
      }

      writer.WriteStartArray();

      for (int i = 0; i < values.Count; i++)
      {
        object value = values[i];

        if (ShouldWriteReference(value, null))
        {
          WriteReference(writer, value);
        }
        else
        {
          if (!CheckForCircularReference(value, null))
            continue;

          SerializeValue(writer, value, null);
        }
      }

      writer.WriteEndArray();

      if (isReference)
      {
        writer.WriteEndObject();
      }

      SerializeStack.RemoveAt(SerializeStack.Count - 1);

      contract.InvokeOnSerialized(values);
    }
开发者ID:oduma,项目名称:Sciendo.Fitas.Droid,代码行数:55,代码来源:JsonSerializerWriter.cs

示例6: SerializeMultidimensionalArray

 private void SerializeMultidimensionalArray(JsonWriter writer, Array values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
 {
   contract.InvokeOnSerializing((object) values, this.Serializer.Context);
   this._serializeStack.Add((object) values);
   bool flag = this.WriteStartArray(writer, (object) values, contract, member, collectionContract, containerProperty);
   this.SerializeMultidimensionalArray(writer, values, contract, member, writer.Top, new int[0]);
   if (flag)
     writer.WriteEndObject();
   this._serializeStack.RemoveAt(this._serializeStack.Count - 1);
   contract.InvokeOnSerialized((object) values, this.Serializer.Context);
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:11,代码来源:JsonSerializerInternalWriter.cs

示例7: SerializeList

 private void SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
 {
   contract.InvokeOnSerializing(values.UnderlyingCollection, this.Serializer.Context);
   this._serializeStack.Add(values.UnderlyingCollection);
   bool flag = this.WriteStartArray(writer, values.UnderlyingCollection, contract, member, collectionContract, containerProperty);
   writer.WriteStartArray();
   int top = writer.Top;
   int num = 0;
   foreach (object obj in (IEnumerable) values)
   {
     try
     {
       JsonContract jsonContract = contract.FinalItemContract ?? this.GetContractSafe(obj);
       if (this.ShouldWriteReference(obj, (JsonProperty) null, jsonContract, (JsonContainerContract) contract, member))
         this.WriteReference(writer, obj);
       else if (this.CheckForCircularReference(writer, obj, (JsonProperty) null, jsonContract, (JsonContainerContract) contract, member))
         this.SerializeValue(writer, obj, jsonContract, (JsonProperty) null, (JsonContainerContract) contract, member);
     }
     catch (Exception ex)
     {
       if (this.IsErrorHandled(values.UnderlyingCollection, (JsonContract) contract, (object) num, writer.ContainerPath, ex))
         this.HandleError(writer, top);
       else
         throw;
     }
     finally
     {
       ++num;
     }
   }
   writer.WriteEndArray();
   if (flag)
     writer.WriteEndObject();
   this._serializeStack.RemoveAt(this._serializeStack.Count - 1);
   contract.InvokeOnSerialized(values.UnderlyingCollection, this.Serializer.Context);
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:36,代码来源:JsonSerializerInternalWriter.cs

示例8: SerializeList

        private void SerializeList(JsonWriter writer, IWrappedCollection values, JsonArrayContract contract, JsonProperty member, JsonContract collectionValueContract)
        {
            contract.InvokeOnSerializing(values.UnderlyingCollection, Serializer.Context);

            SerializeStack.Add(values.UnderlyingCollection);
            
            bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Arrays);
            bool includeTypeDetails = ShouldWriteType(TypeNameHandling.Arrays, contract, member, collectionValueContract);

            if (isReference || includeTypeDetails)
            {
                writer.WriteStartObject();

                if (isReference)
                {
                    writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
                    writer.WriteValue(Serializer.ReferenceResolver.GetReference(this, values.UnderlyingCollection));
                }
                if (includeTypeDetails)
                {
                    WriteTypeProperty(writer, values.UnderlyingCollection.GetType());
                }
                writer.WritePropertyName(JsonTypeReflector.ArrayValuesPropertyName);
            }

            JsonContract childValuesContract = Serializer.ContractResolver.ResolveContract(contract.CollectionItemType ?? typeof(object));

            writer.WriteStartArray();

            int initialDepth = writer.Top;

            int index = 0;
            // note that an error in the IEnumerable won't be caught
            foreach (object value in values)
            {
                try
                {

                    // Note: So apparently the type of the items in the list are being retrieved already in the childValuesContract.  Check to see
                    // if the type here is correct, and check to see if the contract retrieved here is the same as the childValuesContract.
                    JsonContract valueContract = childValuesContract;
 
                    if(value !=  null)
                        valueContract = Serializer.ContractResolver.ResolveContract(value.GetType());
 
                    //JsonContract valueContract = GetContractSafe(value);

                    if (ShouldWriteReference(value, null, valueContract))
                    {
                        WriteReference(writer, value);
                    }
                    else
                    {
                        if (CheckForCircularReference(value, null, contract))
                        {
                            SerializeValue(writer, value, valueContract, null, childValuesContract);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (IsErrorHandled(values.UnderlyingCollection, contract, index, ex))
                        HandleError(writer, initialDepth);
                    else
                        throw;
                }
                finally
                {
                    index++;
                }
            }

            writer.WriteEndArray();

            if (isReference || includeTypeDetails)
            {
                writer.WriteEndObject();
            }

            SerializeStack.RemoveAt(SerializeStack.Count - 1);

            contract.InvokeOnSerialized(values.UnderlyingCollection, Serializer.Context);
        }
开发者ID:TSASoftware,项目名称:Json.Net,代码行数:83,代码来源:JsonSerializerInternalWriter.cs


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