private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContract collectionValueContract)
        {
            contract.InvokeOnSerializing(values.UnderlyingDictionary, base.Serializer.Context);
            SerializeStack.Add(values.UnderlyingDictionary);
            writer.WriteStartObject();
            bool?isReference = contract.IsReference;

            if ((!isReference.HasValue) ? HasFlag(base.Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects) : isReference.Value)
            {
                writer.WritePropertyName("$id");
                writer.WriteValue(base.Serializer.ReferenceResolver.GetReference(this, values.UnderlyingDictionary));
            }
            if (ShouldWriteType(TypeNameHandling.Objects, contract, member, collectionValueContract))
            {
                WriteTypeProperty(writer, values.UnderlyingDictionary.GetType());
            }
            JsonContract          collectionValueContract2 = base.Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));
            int                   top        = writer.Top;
            IDictionaryEnumerator enumerator = values.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    DictionaryEntry entry        = (DictionaryEntry)enumerator.Current;
                    string          propertyName = GetPropertyName(entry);
                    propertyName = ((contract.PropertyNameResolver == null) ? propertyName : contract.PropertyNameResolver(propertyName));
                    try
                    {
                        object       value        = entry.Value;
                        JsonContract contractSafe = GetContractSafe(value);
                        if (ShouldWriteReference(value, null, contractSafe))
                        {
                            writer.WritePropertyName(propertyName);
                            WriteReference(writer, value);
                        }
                        else if (CheckForCircularReference(value, null, contract))
                        {
                            writer.WritePropertyName(propertyName);
                            SerializeValue(writer, value, contractSafe, null, collectionValueContract2);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, ex))
                        {
                            throw;
                        }
                        HandleError(writer, top);
                    }
                }
            }
            finally
            {
                (enumerator as IDisposable)?.Dispose();
            }
            writer.WriteEndObject();
            SerializeStack.RemoveAt(SerializeStack.Count - 1);
            contract.InvokeOnSerialized(values.UnderlyingDictionary, base.Serializer.Context);
        }
Esempio n. 2
0
        private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContract collectionValueContract)
        {
            contract.InvokeOnSerializing(values.UnderlyingDictionary, base.Serializer.Context);
            SerializeStack.Add(values.UnderlyingDictionary);
            writer.WriteStartObject();
            if (contract.IsReference ?? HasFlag(base.Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects))
            {
                writer.WritePropertyName("$id");
                writer.WriteValue(base.Serializer.ReferenceResolver.GetReference(this, values.UnderlyingDictionary));
            }
            if (ShouldWriteType(TypeNameHandling.Objects, contract, member, collectionValueContract))
            {
                WriteTypeProperty(writer, values.UnderlyingDictionary.GetType());
            }
            JsonContract collectionValueContract2 = base.Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));
            int          top = writer.Top;

            foreach (DictionaryEntry value2 in values)
            {
                string propertyName = GetPropertyName(value2);
                propertyName = ((contract.PropertyNameResolver != null) ? contract.PropertyNameResolver(propertyName) : propertyName);
                try
                {
                    object       value        = value2.Value;
                    JsonContract contractSafe = GetContractSafe(value);
                    if (ShouldWriteReference(value, null, contractSafe))
                    {
                        writer.WritePropertyName(propertyName);
                        WriteReference(writer, value);
                    }
                    else if (CheckForCircularReference(value, null, contract))
                    {
                        writer.WritePropertyName(propertyName);
                        SerializeValue(writer, value, contractSafe, null, collectionValueContract2);
                    }
                }
                catch (Exception ex)
                {
                    if (IsErrorHandled(values.UnderlyingDictionary, contract, propertyName, ex))
                    {
                        HandleError(writer, top);
                        continue;
                    }
                    throw;
                }
            }
            writer.WriteEndObject();
            SerializeStack.RemoveAt(SerializeStack.Count - 1);
            contract.InvokeOnSerialized(values.UnderlyingDictionary, base.Serializer.Context);
        }
Esempio n. 3
0
        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);
        }
        private void SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract)
        {
            contract.InvokeOnSerializing(values);

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

            bool isReference = contract.IsReference ?? HasFlag(_serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects);

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

            foreach (DictionaryEntry entry in values)
            {
                string propertyName = entry.Key.ToString();
                object value        = entry.Value;

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

                    writer.WritePropertyName(propertyName);
                    SerializeValue(writer, value, null);
                }
            }

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

            contract.InvokeOnSerialized(values);
        }
    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);
    }
Esempio n. 6
0
        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;
                    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;
                    }
                }
            }

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

            contract.InvokeOnSerialized(values.UnderlyingDictionary, Serializer.Context);
        }
		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;
//				}
//			});


//#endif
			

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

			contract.InvokeOnSerialized(values.UnderlyingDictionary, Serializer.Context);
		}
        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(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);

            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;
            }
              }

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

              contract.InvokeOnSerialized(values.UnderlyingDictionary, Serializer.Context);
        }
    private void SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract)
    {
      contract.InvokeOnSerializing(values);

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

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

      foreach (DictionaryEntry entry in values)
      {
        string propertyName = entry.Key.ToString();
        object value = entry.Value;

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

          writer.WritePropertyName(propertyName);
          SerializeValue(writer, value, null);
        }
      }

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

      contract.InvokeOnSerialized(values);
    }
Esempio n. 10
0
        private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonContract collectionValueContract)
        {
            contract.InvokeOnSerializing(values.UnderlyingDictionary, Serializer.Context);

            _serializeStack.Add(values.UnderlyingDictionary);

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

            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;

            // 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 = dictionaryValueContract ?? GetContractSafe(value);

                    if (ShouldWriteReference(value, null, valueContract, contract))
                    {
                        writer.WritePropertyName(propertyName);
                        WriteReference(writer, value);
                    }
                    else
                    {
                        if (!CheckForCircularReference(value, null, valueContract, 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);
        }
        private void SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract)
        {
            contract.InvokeOnSerializing(values);

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

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

              int initialDepth = writer.Top;

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

            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))
              continue;

            writer.WritePropertyName(propertyName);

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

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

              contract.InvokeOnSerialized(values);
        }
        private void SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract)
        {
            contract.InvokeOnSerializing(values);

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

            bool isReference = contract.IsReference ?? HasFlag(Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects);

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

            int initialDepth = writer.Top;

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

                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))
                        {
                            continue;
                        }

                        writer.WritePropertyName(propertyName);

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

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

            contract.InvokeOnSerialized(values);
        }
Esempio n. 13
0
 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);
 }
        private void SerializeDictionary(JsonWriter writer, IWrappedDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContract collectionValueContract)
        {
            contract.InvokeOnSerializing(values.UnderlyingDictionary, base.Serializer.Context);
            this.SerializeStack.Add(values.UnderlyingDictionary);
            writer.WriteStartObject();
            bool?isReference = contract.IsReference;
            bool flag        = (!isReference.get_HasValue()) ? this.HasFlag(base.Serializer.PreserveReferencesHandling, PreserveReferencesHandling.Objects) : isReference.get_Value();

            if (flag)
            {
                writer.WritePropertyName("$id");
                writer.WriteValue(base.Serializer.ReferenceResolver.GetReference(this, values.UnderlyingDictionary));
            }
            if (this.ShouldWriteType(TypeNameHandling.Objects, contract, member, collectionValueContract))
            {
                this.WriteTypeProperty(writer, values.UnderlyingDictionary.GetType());
            }
            JsonContract          collectionValueContract2 = base.Serializer.ContractResolver.ResolveContract(contract.DictionaryValueType ?? typeof(object));
            int                   top        = writer.Top;
            IDictionaryEnumerator enumerator = values.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    DictionaryEntry entry = (DictionaryEntry)enumerator.get_Current();
                    string          text  = this.GetPropertyName(entry);
                    text = ((contract.PropertyNameResolver == null) ? text : contract.PropertyNameResolver.Invoke(text));
                    try
                    {
                        object       value        = entry.get_Value();
                        JsonContract contractSafe = this.GetContractSafe(value);
                        if (this.ShouldWriteReference(value, null, contractSafe))
                        {
                            writer.WritePropertyName(text);
                            this.WriteReference(writer, value);
                        }
                        else if (this.CheckForCircularReference(value, default(ReferenceLoopHandling?), contract))
                        {
                            writer.WritePropertyName(text);
                            this.SerializeValue(writer, value, contractSafe, null, collectionValueContract2);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (!base.IsErrorHandled(values.UnderlyingDictionary, contract, text, ex))
                        {
                            throw;
                        }
                        this.HandleError(writer, top);
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            writer.WriteEndObject();
            this.SerializeStack.RemoveAt(this.SerializeStack.get_Count() - 1);
            contract.InvokeOnSerialized(values.UnderlyingDictionary, base.Serializer.Context);
        }