private void SerializeDynamicObject(IDynamicMetaObjectProvider dynamicObject, bool startEle) { var flag = new AssertFlag(); var dymgr = new DynamicManager(); if (startEle) { xmlWriter.WriteStartElement("Dynamic"); } foreach (var name in dynamicObject.GetDynamicMemberNames()) { object value; dymgr.TryGetMember(dynamicObject, name, out value); if (value == null) { continue; } xmlWriter.WriteStartElement(name); Serialize(value); xmlWriter.WriteEndElement(); } if (startEle) { xmlWriter.WriteEndElement(); } }
/// <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); }
private void SerializeDynamicObject(IDynamicMetaObjectProvider dynamicObject, bool startEle) { var flag = new AssertFlag(); var dymgr = new DynamicManager(); if (startEle) { xmlWriter.WriteStartElement("Dynamic"); } var queue = new PriorityActionQueue(); foreach (var name in dynamicObject.GetDynamicMemberNames()) { object value; dymgr.TryGetMember(dynamicObject, name, out value); if (value == null) { continue; } if (option.NodeStyle == XmlNodeStyle.Attribute && value.GetType().IsStringable()) { queue.Add(0, () => { context.SerializeInfo = new PropertySerialzeInfo(ObjectType.DynamicObject, typeof(object), name); xmlWriter.WriteAttributeString(name, value.ToString()); context.SerializeInfo = null; }); } else { queue.Add(1, () => { context.SerializeInfo = new PropertySerialzeInfo(ObjectType.DynamicObject, typeof(object), name); WriteXmlElement(name, true, () => Serialize(value, type: value.GetType())); context.SerializeInfo = null; }); } } queue.Invoke(); if (startEle) { xmlWriter.WriteEndElement(); } }
private void SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) { OnSerializing(writer, contract, value); _serializeStack.Add(value); WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty); int initialDepth = writer.Top; for (int index = 0; index < contract.Properties.Count; index++) { JsonProperty property = contract.Properties[index]; // only write non-dynamic properties that have an explicit attribute if (property.HasMemberAttribute) { try { object memberValue; JsonContract memberContract; if (!CalculatePropertyValues(writer, value, contract, member, property, out memberContract, out memberValue)) { continue; } property.WritePropertyName(writer); SerializeValue(writer, memberValue, memberContract, property, contract, member); } catch (Exception ex) { if (IsErrorHandled(value, contract, property.PropertyName, null, writer.ContainerPath, ex)) { HandleError(writer, initialDepth); } else { throw; } } } } foreach (string memberName in value.GetDynamicMemberNames()) { object memberValue; if (contract.TryGetMember(value, memberName, out memberValue)) { try { JsonContract valueContract = GetContractSafe(memberValue); if (!ShouldWriteDynamicProperty(memberValue)) { continue; } if (CheckForCircularReference(writer, memberValue, null, valueContract, contract, member)) { string resolvedPropertyName = (contract.PropertyNameResolver != null) ? contract.PropertyNameResolver(memberName) : memberName; writer.WritePropertyName(resolvedPropertyName); SerializeValue(writer, memberValue, valueContract, null, contract, member); } } catch (Exception ex) { if (IsErrorHandled(value, contract, memberName, null, writer.ContainerPath, ex)) { HandleError(writer, initialDepth); } else { throw; } } } } writer.WriteEndObject(); _serializeStack.RemoveAt(_serializeStack.Count - 1); OnSerialized(writer, contract, value); }
private void SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract 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) { // only write non-dynamic properties that have an explicit attribute if (property.HasMemberAttribute) { 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; } } } foreach (string memberName in value.GetDynamicMemberNames()) { object memberValue; if (value.TryGetMember(memberName, out memberValue)) { try { string resolvedPropertyName = (contract.PropertyNameResolver != null) ? contract.PropertyNameResolver(memberName) : memberName; writer.WritePropertyName(resolvedPropertyName); SerializeValue(writer, memberValue, GetContractSafe(memberValue), null, null, member); } catch (Exception ex) { if (IsErrorHandled(value, contract, memberName, writer.ContainerPath, ex)) HandleError(writer, initialDepth); else throw; } } } writer.WriteEndObject(); _serializeStack.RemoveAt(_serializeStack.Count - 1); contract.InvokeOnSerialized(value, Serializer.Context); }
private void SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) { OnSerializing(writer, contract, value); _serializeStack.Add(value); WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty); int initialDepth = writer.Top; for (int index = 0; index < contract.Properties.Count; index++) { JsonProperty property = contract.Properties[index]; // only write non-dynamic properties that have an explicit attribute if (property.HasMemberAttribute) { try { object memberValue; JsonContract memberContract; if (!CalculatePropertyValues(writer, value, contract, member, property, out memberContract, out memberValue)) continue; property.WritePropertyName(writer); SerializeValue(writer, memberValue, memberContract, property, contract, member); } catch (Exception ex) { if (IsErrorHandled(value, contract, property.PropertyName, null, writer.ContainerPath, ex)) HandleError(writer, initialDepth); else throw; } } } foreach (string memberName in value.GetDynamicMemberNames()) { object memberValue; if (contract.TryGetMember(value, memberName, out memberValue)) { try { JsonContract valueContract = GetContractSafe(memberValue); if (!ShouldWriteDynamicProperty(memberValue)) continue; if (CheckForCircularReference(writer, memberValue, null, valueContract, contract, member)) { string resolvedPropertyName = (contract.PropertyNameResolver != null) ? contract.PropertyNameResolver(memberName) : memberName; writer.WritePropertyName(resolvedPropertyName); SerializeValue(writer, memberValue, valueContract, null, contract, member); } } catch (Exception ex) { if (IsErrorHandled(value, contract, memberName, null, writer.ContainerPath, ex)) HandleError(writer, initialDepth); else throw; } } } writer.WriteEndObject(); _serializeStack.RemoveAt(_serializeStack.Count - 1); OnSerialized(writer, contract, value); }
private void SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) { this.OnSerializing(writer, contract, value); this._serializeStack.Add(value); this.WriteObjectStart(writer, value, contract, member, collectionContract, containerProperty); int top = writer.Top; for (int i = 0; i < contract.Properties.Count; i++) { JsonProperty jsonProperty = contract.Properties[i]; if (jsonProperty.HasMemberAttribute) { try { JsonContract valueContract; object value2; if (this.CalculatePropertyValues(writer, value, contract, member, jsonProperty, out valueContract, out value2)) { jsonProperty.WritePropertyName(writer); this.SerializeValue(writer, value2, valueContract, jsonProperty, contract, member); } } catch (Exception ex) { if (!base.IsErrorHandled(value, contract, jsonProperty.PropertyName, null, writer.ContainerPath, ex)) { throw; } this.HandleError(writer, top); } } } foreach (string current in value.GetDynamicMemberNames()) { object obj; if (contract.TryGetMember(value, current, out obj)) { try { JsonContract contractSafe = this.GetContractSafe(obj); if (this.ShouldWriteDynamicProperty(obj)) { if (this.CheckForCircularReference(writer, obj, null, contractSafe, contract, member)) { string name = (contract.PropertyNameResolver != null) ? contract.PropertyNameResolver(current) : current; writer.WritePropertyName(name); this.SerializeValue(writer, obj, contractSafe, null, contract, member); } } } catch (Exception ex2) { if (!base.IsErrorHandled(value, contract, current, null, writer.ContainerPath, ex2)) { throw; } this.HandleError(writer, top); } } } writer.WriteEndObject(); this._serializeStack.RemoveAt(this._serializeStack.Count - 1); this.OnSerialized(writer, contract, value); }
private void SerializeDynamic(JsonWriter writer, IDynamicMetaObjectProvider value, JsonDynamicContract 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) { // only write non-dynamic properties that have an explicit attribute if (property.HasMemberAttribute) { 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; } } } } foreach (string memberName in value.GetDynamicMemberNames()) { object memberValue; if (value.TryGetMember(memberName, out memberValue)) { try { string resolvedPropertyName = (contract.PropertyNameResolver != null) ? contract.PropertyNameResolver(memberName) : memberName; writer.WritePropertyName(resolvedPropertyName); SerializeValue(writer, memberValue, GetContractSafe(memberValue), null, null, member); } catch (Exception ex) { if (IsErrorHandled(value, contract, memberName, writer.ContainerPath, ex)) { HandleError(writer, initialDepth); } else { throw; } } } } writer.WriteEndObject(); _serializeStack.RemoveAt(_serializeStack.Count - 1); contract.InvokeOnSerialized(value, Serializer.Context); }
// Token: 0x0600155F RID: 5471 RVA: 0x00066510 File Offset: 0x00064710 private void xmethod_3931(Class_296 arg_0, IDynamicMetaObjectProvider arg_1, Class_365 arg_2, Class_454 arg_3, Class_350 arg_4, Class_454 arg_5) { this.vmethod_3915(arg_0, arg_2, arg_1); this.field_2.Add(arg_1); this.pmethod_3919(arg_0, arg_1, arg_2, arg_3, arg_4, arg_5); int sayıInt_ = arg_0.prop_1; for (int i = 0; i < arg_2.prop_0.Count; i++) { Class_454 class_ = arg_2.prop_0[i]; if (class_.prop_13) { try { Class_349 arg_6; object obje_; if (this.lmethod_3918(arg_0, arg_1, arg_2, arg_3, class_, out arg_6, out obje_)) { class_.xmethod_3701(arg_0); this.dmethod_3906(arg_0, obje_, arg_6, class_, arg_2, arg_3); } } catch (Exception arg_7) { if (!base.smethod_3850(arg_1, arg_2, class_.prop_1, null, arg_0.prop_3, arg_7)) { throw; } this.dmethod_3936(arg_0, sayıInt_); } } } foreach (string text in arg_1.GetDynamicMemberNames()) { object obje_2; if (arg_2.xmethod_2641(arg_1, text, out obje_2)) { try { Class_349 class_2 = this.cmethod_3904(obje_2); if (this.tmethod_3932(obje_2)) { if (this.smethod_3910(arg_0, obje_2, null, class_2, arg_2, arg_3)) { string str_ = (arg_2.prop_1 != null) ? arg_2.prop_1(text) : text; arg_0.gmethod_2013(str_); this.dmethod_3906(arg_0, obje_2, class_2, null, arg_2, arg_3); } } } catch (Exception arg_8) { if (!base.smethod_3850(arg_1, arg_2, text, null, arg_0.prop_3, arg_8)) { throw; } this.dmethod_3936(arg_0, sayıInt_); } } } arg_0.lmethod_2008(); this.field_2.RemoveAt(this.field_2.Count - 1); this.dmethod_3916(arg_0, arg_2, arg_1); }