private void SerializeDictionary(JsonWriter writer, IDictionary values) { writer.WriteStartObject(); foreach (DictionaryEntry entry in values) { writer.WritePropertyName(entry.Key.ToString()); SerializeValue(writer, entry.Value, null); } writer.WriteEndObject(); }
private void WriteMemberInfoProperty(JsonWriter writer, object value, JsonMemberMapping memberMapping) { MemberInfo member = memberMapping.Member; string propertyName = memberMapping.MappingName; JsonConverter memberConverter = memberMapping.MemberConverter; object defaultValue = memberMapping.DefaultValue; if (!ReflectionUtils.IsIndexedProperty(member)) { object memberValue = ReflectionUtils.GetMemberValue(member, value); if (_nullValueHandling == NullValueHandling.Ignore && memberValue == null) return; if (_defaultValueHandling == DefaultValueHandling.Ignore && object.Equals(memberValue, defaultValue)) return; if (writer.SerializeStack.IndexOf(memberValue) != -1) { switch (_referenceLoopHandling) { case ReferenceLoopHandling.Error: throw new JsonSerializationException("Self referencing loop"); case ReferenceLoopHandling.Ignore: // return from method return; case ReferenceLoopHandling.Serialize: // continue break; default: throw new InvalidOperationException("Unexpected ReferenceLoopHandling value: '{0}'".FormatWith(CultureInfo.InvariantCulture, _referenceLoopHandling)); } } writer.WritePropertyName(propertyName ?? member.Name); SerializeValue(writer, memberValue, memberConverter); } }