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


C# JsonDictionaryContract.PropertyNameResolver方法代码示例

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


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

示例1: SerializeDictionary

    private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
    {
      contract.InvokeOnSerializing(values.UnderlyingDictionary, Serializer.Context);

      _serializeStack.Add(values.UnderlyingDictionary);

      WriteObjectStart(writer, values.UnderlyingDictionary, contract, member, collectionContract, containerProperty);

      if (contract.ItemContract == null)
        contract.ItemContract = Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));

      int initialDepth = writer.Top;

      // Mono Unity 3.0 fix
      IWrappedDictionary d = values;

      foreach (DictionaryEntry entry in d)
      {
        string propertyName = GetPropertyName(entry);

        propertyName = (contract.PropertyNameResolver != null)
                         ? contract.PropertyNameResolver(propertyName)
                         : propertyName;

        try
        {
          object value = entry.Value;
          JsonContract valueContract = contract.FinalItemContract ?? GetContractSafe(value);

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

            writer.WritePropertyName(propertyName);

            SerializeValue(writer, value, valueContract, null, contract, member);
          }
        }
        catch (Exception ex)
        {
          if (IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, writer.ContainerPath, ex))
            HandleError(writer, initialDepth);
          else
            throw;
        }
      }

      writer.WriteEndObject();

      _serializeStack.RemoveAt(_serializeStack.Count - 1);

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

示例2: SerializeDictionary

        private void SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
        {
            IWrappedDictionary wrappedDictionary = values as IWrappedDictionary;
            object underlyingDictionary = wrappedDictionary != null ? wrappedDictionary.UnderlyingDictionary : values;

            OnSerializing(writer, contract, underlyingDictionary);
            _serializeStack.Add(underlyingDictionary);

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

            if (contract.ItemContract == null)
                contract.ItemContract = Serializer._contractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));

            if (contract.KeyContract == null)
                contract.KeyContract = Serializer._contractResolver.ResolveContract(contract.DictionaryKeyType ?? typeof(object));

            int initialDepth = writer.Top;

            foreach (DictionaryEntry entry in values)
            {
                bool escape;
                string propertyName = GetPropertyName(writer, entry.Key, contract.KeyContract, out escape);

                propertyName = (contract.PropertyNameResolver != null)
                    ? contract.PropertyNameResolver(propertyName)
                    : propertyName;

                try
                {
                    object value = entry.Value;
                    JsonContract valueContract = contract.FinalItemContract ?? GetContractSafe(value);

                    if (ShouldWriteReference(value, null, valueContract, contract, member))
                    {
                        writer.WritePropertyName(propertyName, escape);
                        WriteReference(writer, value);
                    }
                    else
                    {
                        if (!CheckForCircularReference(writer, value, null, valueContract, contract, member))
                            continue;

                        writer.WritePropertyName(propertyName, escape);

                        SerializeValue(writer, value, valueContract, null, contract, member);
                    }
                }
                catch (Exception ex)
                {
                    if (IsErrorHandled(underlyingDictionary, contract, propertyName, null, writer.ContainerPath, ex))
                        HandleError(writer, initialDepth);
                    else
                        throw;
                }
            }

            writer.WriteEndObject();

            _serializeStack.RemoveAt(_serializeStack.Count - 1);

            OnSerialized(writer, contract, underlyingDictionary);
        }
开发者ID:OndrejPetrzilka,项目名称:Newtonsoft.Json,代码行数:62,代码来源:JsonSerializerInternalWriter.cs

示例3: SerializeDictionary

		private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContract collectionValueContract)
		{
			contract.InvokeOnSerializing(values.UnderlyingDictionary, Serializer.Context);

			SerializeStack.Add(values.UnderlyingDictionary);
			writer.WriteStartObject();

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

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

			int initialDepth = writer.Top;

			// Mono Unity 3.0 fix
			IDictionary d = values;
//#if !(UNITY_IPHONE || UNITY_IOS)
			foreach (DictionaryEntry entry in d)
			{
				string propertyName = GetPropertyName(entry);

				propertyName = (contract.PropertyNameResolver != null)
								 ? contract.PropertyNameResolver(propertyName)
								 : propertyName;
				try
				{
					object value = entry.Value;
					JsonContract valueContract = GetContractSafe(value);

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

						writer.WritePropertyName(propertyName);

						SerializeValue(writer, value, valueContract, null, childValuesContract);
					}
				}
				catch (Exception ex)
				{
					if (IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, ex))
						HandleError(writer, initialDepth);
					else
						throw;
				}
			}
//#else
//			string propertyName;

//			d.ForEach(originalEntry =>
//			{
//				var entry = (DictionaryEntry)originalEntry;

//				propertyName = GetPropertyName(entry);

//				propertyName = (contract.PropertyNameResolver != null)
//								 ? contract.PropertyNameResolver(propertyName)
//								 : propertyName;

//				try
//				{
//					object value = entry.Value;
//					JsonContract valueContract = GetContractSafe(value);

//					if (ShouldWriteReference(value, null, valueContract))
//					{
//						writer.WritePropertyName(propertyName);
//						WriteReference(writer, value);
//					}
//					else
//					{
//						if (!CheckForCircularReference(value, null, contract))
//							return;

//						writer.WritePropertyName(propertyName);

//						SerializeValue(writer, value, valueContract, null, childValuesContract);
//					}
//				}
//				catch (Exception ex)
//				{
//					if (IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, ex))
//						HandleError(writer, initialDepth);
//					else
//						throw;
//				}
//.........这里部分代码省略.........
开发者ID:JungWon2,项目名称:memory_book,代码行数:101,代码来源:JsonSerializerInternalWriter.cs

示例4: SerializeDictionary

    private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContract collectionValueContract)
    {
      contract.InvokeOnSerializing(values.UnderlyingDictionary, Serializer.Context);

      _serializeStack.Add(values.UnderlyingDictionary);
      writer.WriteStartObject();

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

      if (contract.DictionaryValueContract == null)
        contract.DictionaryValueContract = Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));

      JsonContract dictionaryValueContract = (contract.DictionaryValueContract.UnderlyingType.IsSealed()) ? contract.DictionaryValueContract : null;

      int initialDepth = writer.Top;

#if !NETFX_CORE
      // Mono Unity 3.0 fix
      IDictionary d = values;
#else
      IWrappedDictionary d = values;
#endif

      foreach (DictionaryEntry entry in d)
      {
        string propertyName = GetPropertyName(entry);

        propertyName = (contract.PropertyNameResolver != null)
                         ? contract.PropertyNameResolver(propertyName)
                         : propertyName;

        try
        {
          object value = entry.Value;
          JsonContract valueContract = dictionaryValueContract ?? GetContractSafe(value);

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

            writer.WritePropertyName(propertyName);

            SerializeValue(writer, value, valueContract, null, contract.DictionaryValueContract);
          }
        }
        catch (Exception ex)
        {
          if (IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, writer.ContainerPath, ex))
            HandleError(writer, initialDepth);
          else
            throw;
        }
      }

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

      contract.InvokeOnSerialized(values.UnderlyingDictionary, Serializer.Context);
    }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:74,代码来源:JsonSerializerInternalWriter.cs

示例5: CreateDictionarySchema

        private Schema CreateDictionarySchema(JsonDictionaryContract dictionaryContract)
        {
            var keyType = dictionaryContract.DictionaryKeyType ?? typeof(object);
            var valueType = dictionaryContract.DictionaryValueType ?? typeof(object);

            if (keyType.IsEnum)
            {
                return new Schema
                {
                    type = "object",
                    properties = Enum.GetNames(keyType).ToDictionary(
                        (name) => dictionaryContract.PropertyNameResolver(name),
                        (name) => CreateInlineSchema(valueType)
                    )
                };
            }
            else
            {
                return new Schema
                {
                    type = "object",
                    additionalProperties = CreateInlineSchema(valueType)
                };
            }
        }
开发者ID:RobStand,项目名称:Swashbuckle,代码行数:25,代码来源:SchemaRegistry.cs

示例6: SerializeDictionary

 private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
 {
   contract.InvokeOnSerializing(values.UnderlyingDictionary, this.Serializer.Context);
   this._serializeStack.Add(values.UnderlyingDictionary);
   this.WriteObjectStart(writer, values.UnderlyingDictionary, (JsonContract) contract, member, collectionContract, containerProperty);
   if (contract.ItemContract == null)
     contract.ItemContract = this.Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof (object));
   int top = writer.Top;
   foreach (DictionaryEntry entry in (IDictionary) values)
   {
     string propertyName = this.GetPropertyName(entry);
     string name = contract.PropertyNameResolver != null ? contract.PropertyNameResolver(propertyName) : propertyName;
     try
     {
       object obj = entry.Value;
       JsonContract jsonContract = contract.FinalItemContract ?? this.GetContractSafe(obj);
       if (this.ShouldWriteReference(obj, (JsonProperty) null, jsonContract, (JsonContainerContract) contract, member))
       {
         writer.WritePropertyName(name);
         this.WriteReference(writer, obj);
       }
       else if (this.CheckForCircularReference(writer, obj, (JsonProperty) null, jsonContract, (JsonContainerContract) contract, member))
       {
         writer.WritePropertyName(name);
         this.SerializeValue(writer, obj, jsonContract, (JsonProperty) null, (JsonContainerContract) contract, member);
       }
     }
     catch (Exception ex)
     {
       if (this.IsErrorHandled(values.UnderlyingDictionary, (JsonContract) contract, (object) name, writer.ContainerPath, ex))
         this.HandleError(writer, top);
       else
         throw;
     }
   }
   writer.WriteEndObject();
   this._serializeStack.RemoveAt(this._serializeStack.Count - 1);
   contract.InvokeOnSerialized(values.UnderlyingDictionary, this.Serializer.Context);
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:39,代码来源:JsonSerializerInternalWriter.cs

示例7: SerializeDictionary

        private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContract collectionValueContract)
        {
            contract.InvokeOnSerializing(values.UnderlyingDictionary, Serializer.Context);

            SerializeStack.Add(values.UnderlyingDictionary);
            writer.WriteStartObject();

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

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

            int initialDepth = writer.Top;

            // Mono Unity 3.0 fix
            IDictionary d = values;

            foreach (DictionaryEntry entry in d)
            {
                string propertyName = GetPropertyName(entry);

                propertyName = (contract.PropertyNameResolver != null)
                                 ? contract.PropertyNameResolver(propertyName)
                                 : propertyName;

                try
                {
                    object value = entry.Value;

                    // Note: So apprently the type of the value item in the dictionary is already being retrieved in the childValuesContract.
                    // Check to see if the childValuesContract is the same as the one retrieved here.

                    JsonContract valueContract = childValuesContract;

                    if(value != null)
                        valueContract = Serializer.ContractResolver.ResolveContract(value.GetType());

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

                        writer.WritePropertyName(propertyName);

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

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

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

示例8: SerializeDictionary

 // Token: 0x06000C0A RID: 3082
 // RVA: 0x000479FC File Offset: 0x00045BFC
 private void SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
 {
     IWrappedDictionary wrappedDictionary = values as IWrappedDictionary;
     object obj = (wrappedDictionary != null) ? wrappedDictionary.UnderlyingDictionary : values;
     this.OnSerializing(writer, contract, obj);
     this._serializeStack.Add(obj);
     this.WriteObjectStart(writer, obj, contract, member, collectionContract, containerProperty);
     if (contract.ItemContract == null)
     {
         contract.ItemContract = this.Serializer._contractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));
     }
     if (contract.KeyContract == null)
     {
         contract.KeyContract = this.Serializer._contractResolver.ResolveContract(contract.DictionaryKeyType ?? typeof(object));
     }
     int top = writer.Top;
     foreach (DictionaryEntry dictionaryEntry in values)
     {
         bool escape;
         string text = this.GetPropertyName(writer, dictionaryEntry.Key, contract.KeyContract, out escape);
         text = ((contract.PropertyNameResolver != null) ? contract.PropertyNameResolver(text) : text);
         try
         {
             object value = dictionaryEntry.Value;
             JsonContract jsonContract = contract.FinalItemContract ?? this.GetContractSafe(value);
             if (this.ShouldWriteReference(value, null, jsonContract, contract, member))
             {
                 writer.WritePropertyName(text, escape);
                 this.WriteReference(writer, value);
             }
             else if (this.CheckForCircularReference(writer, value, null, jsonContract, contract, member))
             {
                 writer.WritePropertyName(text, escape);
                 this.SerializeValue(writer, value, jsonContract, null, contract, member);
             }
         }
         catch (Exception ex)
         {
             if (!base.IsErrorHandled(obj, contract, text, null, writer.ContainerPath, ex))
             {
                 throw;
             }
             this.HandleError(writer, top);
         }
     }
     writer.WriteEndObject();
     this._serializeStack.RemoveAt(this._serializeStack.Count - 1);
     this.OnSerialized(writer, contract, obj);
 }
开发者ID:newchild,项目名称:Project-DayZero,代码行数:51,代码来源:JsonSerializerInternalWriter.cs


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