/// <summary> /// Serializes the dynamic. /// </summary> /// <param name="writer">The writer.</param> /// <param name="value">The value.</param> /// <param name="contract">The contract.</param> private void SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract contract) { contract.InvokeOnSerializing(value, this.Serializer.Context); this._serializeStack.Add(value); writer.WriteStartObject(); foreach (string memberName in value.GetDynamicMemberNames()) { object memberValue; if (DynamicUtils.TryGetMember(value, memberName, out memberValue)) { string resolvedPropertyName = (contract.PropertyNameResolver != null) ? contract.PropertyNameResolver(memberName) : memberName; writer.WritePropertyName(resolvedPropertyName); this.SerializeValue(writer, memberValue, this.GetContractSafe(memberValue), null, null); } } writer.WriteEndObject(); this._serializeStack.RemoveAt(this._serializeStack.Count - 1); contract.InvokeOnSerialized(value, this.Serializer.Context); }
/// <summary> /// Serializes the dynamic. /// </summary> /// <param name="writer">The writer.</param> /// <param name="value">The value.</param> /// <param name="contract">The contract.</param> private void SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract contract) { contract.InvokeOnSerializing(value, Serializer.Context); _serializeStack.Add(value); writer.WriteStartObject(); foreach (string memberName in value.GetDynamicMemberNames()) { object memberValue; if (DynamicUtils.TryGetMember(value, memberName, out memberValue)) { string resolvedPropertyName = (contract.PropertyNameResolver != null) ? contract.PropertyNameResolver(memberName) : memberName; writer.WritePropertyName(resolvedPropertyName); SerializeValue(writer, memberValue, GetContractSafe(memberValue), null, null); } } writer.WriteEndObject(); _serializeStack.RemoveAt(_serializeStack.Count - 1); contract.InvokeOnSerialized(value, Serializer.Context); }