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


C# JsonObjectContract.InvokeOnSerializing方法代码示例

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


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

示例1: SerializeObject

		private void SerializeObject(JsonWriter writer, object value, JsonObjectContract contract, JsonProperty member, JsonContract collectionValueContract)
		{
			contract.InvokeOnSerializing(value, Serializer.Context);

			SerializeStack.Add(value);
			writer.WriteStartObject();

			bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects);
			if (isReference)
			{
				writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
				writer.WriteValue(Serializer.ReferenceResolver.GetReference(this, value));
			}
			if (ShouldWriteType(TypeNameHandling.Objects, contract, member, collectionValueContract))
			{
				WriteTypeProperty(writer, contract.UnderlyingType);
			}

			int initialDepth = writer.Top;

			foreach (JsonProperty property in contract.Properties)
			{
				try
				{
					if (!property.Ignored && property.Readable && ShouldSerialize(property, value) && IsSpecified(property, value))
					{
						object memberValue = property.ValueProvider.GetValue(value);
						JsonContract memberContract = GetContractSafe(memberValue);

						WriteMemberInfoProperty(writer, memberValue, property, memberContract);
					}
				}
				catch (Exception ex)
				{
					if (IsErrorHandled(value, contract, property.PropertyName, ex))
						HandleError(writer, initialDepth);
					else
						throw;
				}
			}

			writer.WriteEndObject();
			SerializeStack.RemoveAt(SerializeStack.Count - 1);

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

示例2: SerializeObject

    private void SerializeObject(JsonWriter writer, object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
    {
      contract.InvokeOnSerializing(value, Serializer.Context);

      _serializeStack.Add(value);

      WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty);

      int initialDepth = writer.Top;

      foreach (JsonProperty property in contract.Properties)
      {
        try
        {
          object memberValue;
          JsonContract memberContract;

          if (!CalculatePropertyValues(writer, value, contract, member, property, out memberContract, out memberValue))
            continue;

          writer.WritePropertyName(property.PropertyName);
          SerializeValue(writer, memberValue, memberContract, property, contract, member);
        }
        catch (Exception ex)
        {
          if (IsErrorHandled(value, contract, property.PropertyName, writer.ContainerPath, ex))
            HandleError(writer, initialDepth);
          else
            throw;
        }
      }

      writer.WriteEndObject();

      _serializeStack.RemoveAt(_serializeStack.Count - 1);

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

示例3: SerializeObject

    private void SerializeObject(JsonWriter writer, object value, JsonObjectContract contract)
    {
      contract.InvokeOnSerializing(value);

#if !SILVERLIGHT && !PocketPC
      TypeConverter converter = TypeDescriptor.GetConverter(contract.UnderlyingType);

      // use the objectType's TypeConverter if it has one and can convert to a string
      if (converter != null && !(converter is ComponentConverter) && (converter.GetType() != typeof (TypeConverter) || value is Type))
      {
        if (converter.CanConvertTo(typeof (string)))
        {
          writer.WriteValue(converter.ConvertToInvariantString(value));

          contract.InvokeOnSerialized(value);
          return;
        }
      }
#else
      if (value is Guid || value is Type || value is Uri)
      {
        writer.WriteValue(value.ToString());
        return;
      }
#endif

      SerializeStack.Add(value);
      writer.WriteStartObject();

      bool isReference = contract.IsReference ?? HasFlag(_serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects);
      if (isReference)
      {
        writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
        writer.WriteValue(_serializer.ReferenceResolver.GetReference(value));
      }
      if (HasFlag(_serializer.TypeNameHandling, TypeNameHandling.Objects))
      {
        WriteTypeProperty(writer, contract.UnderlyingType);
      }

      foreach (JsonProperty property in contract.Properties)
      {
        if (!property.Ignored && property.Readable)
          WriteMemberInfoProperty(writer, value, property);
      }

      writer.WriteEndObject();
      SerializeStack.RemoveAt(SerializeStack.Count - 1);

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

示例4: SerializeObject

    private void SerializeObject(JsonWriter writer, object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
    {
      contract.InvokeOnSerializing(value, Serializer.Context);

      _serializeStack.Add(value);

      WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty);

      int initialDepth = writer.Top;

      foreach (JsonProperty property in contract.Properties)
      {
        try
        {
          if (!property.Ignored && property.Readable && ShouldSerialize(property, value) && IsSpecified(property, value))
          {
            if (property.PropertyContract == null)
              property.PropertyContract = Serializer.ContractResolver.ResolveContract(property.PropertyType);

            object memberValue = property.ValueProvider.GetValue(value);
            JsonContract memberContract = (property.PropertyContract.UnderlyingType.IsSealed()) ? property.PropertyContract : GetContractSafe(memberValue);

            if (ShouldWriteProperty(memberValue, property))
            {
              string propertyName = property.PropertyName;

              if (ShouldWriteReference(memberValue, property, memberContract, contract, member))
              {
                writer.WritePropertyName(propertyName);
                WriteReference(writer, memberValue);
                continue;
              }

              if (!CheckForCircularReference(writer, memberValue, property, memberContract, contract, member))
                continue;

              if (memberValue == null)
              {
                Required resolvedRequired = property._required ?? contract.ItemRequired ?? Required.Default;
                if (resolvedRequired == Required.Always)
                  throw JsonSerializationException.Create(null, writer.ContainerPath, "Cannot write a null value for property '{0}'. Property requires a value.".FormatWith(CultureInfo.InvariantCulture, property.PropertyName), null);
              }

              writer.WritePropertyName(propertyName);
              SerializeValue(writer, memberValue, memberContract, property, contract, member);
            }
          }
        }
        catch (Exception ex)
        {
          if (IsErrorHandled(value, contract, property.PropertyName, writer.ContainerPath, ex))
            HandleError(writer, initialDepth);
          else
            throw;
        }
      }

      writer.WriteEndObject();

      _serializeStack.RemoveAt(_serializeStack.Count - 1);

      contract.InvokeOnSerialized(value, Serializer.Context);
    }
开发者ID:taliesins,项目名称:Newtonsoft.Json,代码行数:63,代码来源:JsonSerializerInternalWriter.cs

示例5: SerializeObject

        private void SerializeObject(JsonWriter writer, object value, JsonObjectContract contract)
        {
            contract.InvokeOnSerializing(value);

              string s;
              if (TryConvertToString(value, contract.UnderlyingType, out s))
              {
            writer.WriteValue(s);

            #if !SILVERLIGHT && !PocketPC
            contract.InvokeOnSerialized(value);
            #endif
            return;
              }

              SerializeStack.Add(value);
              writer.WriteStartObject();

              bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects);
              if (isReference)
              {
            writer.WritePropertyName(JsonTypeReflector.IdPropertyName);
            writer.WriteValue(Serializer.ReferenceResolver.GetReference(value));
              }
              if (HasFlag(Serializer.TypeNameHandling, TypeNameHandling.Objects))
              {
            WriteTypeProperty(writer, contract.UnderlyingType);
              }

              int initialDepth = writer.Top;

              foreach (JsonProperty property in contract.Properties)
              {
            try
            {
              if (!property.Ignored && property.Readable)
            WriteMemberInfoProperty(writer, value, property);
            }
            catch (Exception ex)
            {
              if (IsErrorHandled(value, contract, property.Member.Name, ex))
            HandleError(writer, initialDepth);
              else
            throw;
            }
              }

              writer.WriteEndObject();
              SerializeStack.RemoveAt(SerializeStack.Count - 1);

              contract.InvokeOnSerialized(value);
        }
开发者ID:martinbowling,项目名称:GowallaOAuthSample,代码行数:52,代码来源:JsonSerializerInternalWriter.cs

示例6: SerializeObject

    private void SerializeObject(JsonWriter writer, object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract)
    {
      contract.InvokeOnSerializing(value, Serializer.Context);

      _serializeStack.Add(value);

      WriteObjectStart(writer, value, contract, member, collectionContract);

      int initialDepth = writer.Top;

      foreach (JsonProperty property in contract.Properties)
      {
        try
        {
          if (!property.Ignored && property.Readable && ShouldSerialize(property, value) && IsSpecified(property, value))
          {
            if (property.PropertyContract == null)
              property.PropertyContract = Serializer.ContractResolver.ResolveContract(property.PropertyType);

            object memberValue = property.ValueProvider.GetValue(value);
            JsonContract memberContract = (property.PropertyContract.UnderlyingType.IsSealed()) ? property.PropertyContract : GetContractSafe(memberValue);

            if (ShouldWriteProperty(memberValue, property))
            {
              WriteMemberInfoProperty(writer, memberValue, property, memberContract, contract);
            }
          }
        }
        catch (Exception ex)
        {
          if (IsErrorHandled(value, contract, property.PropertyName, writer.ContainerPath, ex))
            HandleError(writer, initialDepth);
          else
            throw;
        }
      }

      writer.WriteEndObject();

      _serializeStack.RemoveAt(_serializeStack.Count - 1);

      contract.InvokeOnSerialized(value, Serializer.Context);
    }
开发者ID:iCooKO,项目名称:Newtonsoft.Json,代码行数:43,代码来源:JsonSerializerInternalWriter.cs

示例7: SerializeObject

 private void SerializeObject(JsonWriter writer, object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
 {
   contract.InvokeOnSerializing(value, this.Serializer.Context);
   this._serializeStack.Add(value);
   this.WriteObjectStart(writer, value, (JsonContract) contract, member, collectionContract, containerProperty);
   int top = writer.Top;
   foreach (JsonProperty jsonProperty in (Collection<JsonProperty>) contract.Properties)
   {
     try
     {
       JsonContract memberContract;
       object memberValue;
       if (this.CalculatePropertyValues(writer, value, (JsonContainerContract) contract, member, jsonProperty, out memberContract, out memberValue))
       {
         writer.WritePropertyName(jsonProperty.PropertyName);
         this.SerializeValue(writer, memberValue, memberContract, jsonProperty, (JsonContainerContract) contract, member);
       }
     }
     catch (Exception ex)
     {
       if (this.IsErrorHandled(value, (JsonContract) contract, (object) jsonProperty.PropertyName, writer.ContainerPath, ex))
         this.HandleError(writer, top);
       else
         throw;
     }
   }
   writer.WriteEndObject();
   this._serializeStack.RemoveAt(this._serializeStack.Count - 1);
   contract.InvokeOnSerialized(value, this.Serializer.Context);
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:30,代码来源:JsonSerializerInternalWriter.cs


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