public PushCurrentMemberInfo ( |
||
memberInfo | ||
Résultat | void |
protected virtual void SerializeText(object obj, XmlWriter writer, SerializationContext state) { //Nothing to serialize if (TextMember == null) { return; } var memberInfo = TextMember; object val; // Get the value of the field/property to be serialized from the object val = memberInfo.GetValue(obj); // If the valuetype field should be treated as null if it is empty then make val null. if (memberInfo.TreatAsNullIfEmpty) { if (memberInfo.ReturnType.IsValueType) { if (Activator.CreateInstance(memberInfo.ReturnType).Equals(val)) { val = null; } } } // Make sure we aren't serializing recursively. if (state.ShouldSerialize(val, memberInfo)) { try { state.PushCurrentMemberInfo(memberInfo); // Get the TypeSerializerWithSimpleTextSupport var simpleSerializer = memberInfo.GetSerializer(obj) as TypeSerializerWithSimpleTextSupport; // Make sure the serializer supports SimpleText if (simpleSerializer == null) { throw new XmlSerializerException(String.Format(TextResources.NoTextSerializerWithSimpleTextSupport, memberInfo.MemberInfo.Name)); } if (memberInfo.SerializeAsCData) { writer.WriteCData(simpleSerializer.Serialize(val, state)); } else { writer.WriteString(simpleSerializer.Serialize(val, state)); } } finally { state.PopCurrentMemberInfo(); } } }
protected virtual void SerializeAttributes(object obj, XmlWriter writer, SerializationContext state) { foreach (SerializationMemberInfo memberInfo in attributeMembersMap.Values) { object val; // Get the value of the field/property to be serialized from the object val = memberInfo.GetValue(obj); // If the valuetype field should be treated as null if it is empty then make val null. if (memberInfo.TreatAsNullIfEmpty) { if (memberInfo.ReturnType.IsValueType) { if (Activator.CreateInstance(memberInfo.ReturnType).Equals(val)) { val = null; } } } // Make sure we aren't serializing recursively. if (state.ShouldSerialize(val, memberInfo)) { try { state.PushCurrentMemberInfo(memberInfo); // Get the TypeSerializerWithSimpleTextSupport var simpleSerializer = memberInfo.GetSerializer(obj) as TypeSerializerWithSimpleTextSupport; // Make sure the serializer supports SimpleText if (simpleSerializer == null) { throw new XmlSerializerException(String.Format(TextResources.NoTextSerializerWithSimpleTextSupport, memberInfo.MemberInfo.Name)); } // Write the start of the attribute. writer.WriteStartAttribute(memberInfo.SerializedName); // Write the attribute value. writer.WriteString(simpleSerializer.Serialize(val, state)); // Write the end of the attribute writer.WriteEndAttribute(); } finally { state.PopCurrentMemberInfo(); } } } }
protected virtual void DeserializeElement(object obj, XmlReader reader, SerializationContext state) { SerializationMemberInfo serializationMember; if (reader.Prefix.Length > 0) { serializationMember = (SerializationMemberInfo)elementMembersMap[state.Parameters.Namespaces.GetNamespace(reader.Prefix) + (char)0xff + reader.LocalName]; } else { serializationMember = (SerializationMemberInfo)elementMembersMap[reader.LocalName]; } if (serializationMember == null) { XmlReaderHelper.ReadAndConsumeMatchingEndElement(reader); } else { state.PushCurrentMemberInfo(serializationMember); try { if (serializationMember.SerializeAsValueNodeAttributeName != null && serializationMember.GetSerializer(reader) is TypeSerializerWithSimpleTextSupport) { var s = reader.GetAttribute(serializationMember.SerializeAsValueNodeAttributeName); var serializer = serializationMember.GetSerializer(reader); serializationMember.SetValue(obj, ((TypeSerializerWithSimpleTextSupport)(serializer)).Deserialize(s, state)); XmlReaderHelper.ReadAndConsumeMatchingEndElement(reader); } else { serializationMember.SetValue(obj, serializationMember.GetSerializer(reader).Deserialize(reader, state)); } } finally { state.PopCurrentMemberInfo(); } } }
protected virtual void DeserializeAttribute(object obj, XmlReader reader, SerializationContext state) { object value; SerializationMemberInfo serializationMember; if (reader.Prefix == "xmlns") { return; } if (reader.Prefix.Length > 0) { serializationMember = (SerializationMemberInfo)attributeMembersMap[state.Parameters.Namespaces.GetNamespace(reader.Prefix) + (char)0xff + reader.LocalName]; } else { serializationMember = (SerializationMemberInfo)attributeMembersMap[reader.Name]; } if (serializationMember == null) { if (obj is ISerializationUnhandledMarkupListener) { ((ISerializationUnhandledMarkupListener)obj).UnhandledAttribute(reader.Name, reader.Value); } return; } state.PushCurrentMemberInfo(serializationMember); try { value = serializationMember.GetSerializer(reader).Deserialize(reader, state); } finally { state.PopCurrentMemberInfo(); } serializationMember.SetValue(obj, value); }
protected virtual void DeserializeText(object obj, XmlReader reader, SerializationContext state) { if (TextMember == null) { return; } state.PushCurrentMemberInfo(TextMember); object value; try { value = TextMember.GetSerializer(reader).Deserialize(reader, state); } finally { state.PopCurrentMemberInfo(); } TextMember.SetValue(obj, value); }
protected virtual void SerializeElements(object obj, XmlWriter writer, SerializationContext state) { foreach (SerializationMemberInfo memberInfo in elementMembersMap.Values) { state.PushCurrentMemberInfo(memberInfo); try { object val; val = memberInfo.GetValue(obj); if (memberInfo.TreatAsNullIfEmpty) { if (memberInfo.ReturnType.IsValueType) { if (Activator.CreateInstance(memberInfo.ReturnType).Equals(val)) { val = null; } } } var serializer = memberInfo.GetSerializer(val); var serializerWithSimpleText = serializer as TypeSerializerWithSimpleTextSupport; if (state.ShouldSerialize(val, memberInfo)) { if (memberInfo.Namespace.Length > 0) { // Write start element with namespace writer.WriteStartElement(state.Parameters.Namespaces.GetPrefix(memberInfo.Namespace), memberInfo.SerializedName, memberInfo.Namespace); } else { // Write start element without namespace writer.WriteStartElement(memberInfo.SerializedName); } if (memberInfo.SerializeAsValueNodeAttributeName != null) { if (serializerWithSimpleText == null) { throw new XmlSerializerException(String.Format(TextResources.NoTextSerializerWithSimpleTextSupport, memberInfo.MemberInfo.Name)); } writer.WriteAttributeString(memberInfo.SerializeAsValueNodeAttributeName, serializerWithSimpleText.Serialize(val, state)); } else if (memberInfo.SerializeAsCData) { if (serializerWithSimpleText == null) { throw new XmlSerializerException(String.Format(TextResources.NoTextSerializerWithSimpleTextSupport, memberInfo.MemberInfo.Name)); } writer.WriteCData(serializerWithSimpleText.Serialize(val, state)); } else { memberInfo.GetSerializer(val).Serialize(val, writer, state); } writer.WriteEndElement(); } } finally { state.PopCurrentMemberInfo(); } } }
protected virtual void SerializeText(object obj, XmlWriter writer, SerializationContext state) { //Nothing to serialize if (TextMember == null) return; var memberInfo = TextMember; object val; // Get the value of the field/property to be serialized from the object val = memberInfo.GetValue(obj); // If the valuetype field should be treated as null if it is empty then make val null. if (memberInfo.TreatAsNullIfEmpty) { if (memberInfo.ReturnType.IsValueType) { if (Activator.CreateInstance(memberInfo.ReturnType).Equals(val)) { val = null; } } } // Make sure we aren't serializing recursively. if (state.ShouldSerialize(val,memberInfo)) { try { state.PushCurrentMemberInfo(memberInfo); // Get the TypeSerializerWithSimpleTextSupport var simpleSerializer = memberInfo.GetSerializer(obj) as TypeSerializerWithSimpleTextSupport; // Make sure the serializer supports SimpleText if (simpleSerializer == null) { throw new XmlSerializerException(String.Format(TextResources.NoTextSerializerWithSimpleTextSupport, memberInfo.MemberInfo.Name)); } if (memberInfo.SerializeAsCData) { writer.WriteCData(simpleSerializer.Serialize(val, state)); } else { writer.WriteString(simpleSerializer.Serialize(val, state)); } } finally { state.PopCurrentMemberInfo(); } } }
protected virtual void SerializeElements(object obj, XmlWriter writer, SerializationContext state) { foreach (SerializationMemberInfo memberInfo in elementMembersMap.Values) { state.PushCurrentMemberInfo(memberInfo); try { object val; val = memberInfo.GetValue(obj); if (memberInfo.TreatAsNullIfEmpty) { if (memberInfo.ReturnType.IsValueType) { if (Activator.CreateInstance(memberInfo.ReturnType).Equals(val)) { val = null; } } } var serializer = memberInfo.GetSerializer(val); var serializerWithSimpleText = serializer as TypeSerializerWithSimpleTextSupport; if (state.ShouldSerialize(val,memberInfo)) { if (memberInfo.Namespace.Length > 0) { // Write start element with namespace writer.WriteStartElement(state.Parameters.Namespaces.GetPrefix(memberInfo.Namespace), memberInfo.SerializedName, memberInfo.Namespace); } else { // Write start element without namespace writer.WriteStartElement(memberInfo.SerializedName); } if (memberInfo.SerializeAsValueNodeAttributeName != null) { if (serializerWithSimpleText == null) { throw new XmlSerializerException(String.Format(TextResources.NoTextSerializerWithSimpleTextSupport, memberInfo.MemberInfo.Name)); } writer.WriteAttributeString(memberInfo.SerializeAsValueNodeAttributeName, serializerWithSimpleText.Serialize(val, state)); } else if (memberInfo.SerializeAsCData) { if (serializerWithSimpleText == null) { throw new XmlSerializerException(String.Format(TextResources.NoTextSerializerWithSimpleTextSupport, memberInfo.MemberInfo.Name)); } writer.WriteCData(serializerWithSimpleText.Serialize(val, state)); } else { memberInfo.GetSerializer(val).Serialize(val, writer, state); } writer.WriteEndElement(); } } finally { state.PopCurrentMemberInfo(); } } }
protected virtual void SerializeAttributes(object obj, XmlWriter writer, SerializationContext state) { foreach (SerializationMemberInfo memberInfo in attributeMembersMap.Values) { object val; // Get the value of the field/property to be serialized from the object val = memberInfo.GetValue(obj); // If the valuetype field should be treated as null if it is empty then make val null. if (memberInfo.TreatAsNullIfEmpty) { if (memberInfo.ReturnType.IsValueType) { if (Activator.CreateInstance(memberInfo.ReturnType).Equals(val)) { val = null; } } } // Make sure we aren't serializing recursively. if (state.ShouldSerialize(val,memberInfo)) { try { state.PushCurrentMemberInfo(memberInfo); // Get the TypeSerializerWithSimpleTextSupport var simpleSerializer = memberInfo.GetSerializer(obj) as TypeSerializerWithSimpleTextSupport; // Make sure the serializer supports SimpleText if (simpleSerializer == null) { throw new XmlSerializerException(String.Format(TextResources.NoTextSerializerWithSimpleTextSupport, memberInfo.MemberInfo.Name)); } // Write the start of the attribute. writer.WriteStartAttribute(memberInfo.SerializedName); // Write the attribute value. writer.WriteString(simpleSerializer.Serialize(val, state)); // Write the end of the attribute writer.WriteEndAttribute(); } finally { state.PopCurrentMemberInfo(); } } } }
protected virtual void DeserializeText(object obj, XmlReader reader, SerializationContext state) { if (TextMember == null) return; state.PushCurrentMemberInfo(TextMember); object value; try { value = TextMember.GetSerializer(reader).Deserialize(reader, state); } finally { state.PopCurrentMemberInfo(); } TextMember.SetValue(obj, value); }
protected virtual void DeserializeElement(object obj, XmlReader reader, SerializationContext state) { SerializationMemberInfo serializationMember; if (reader.Prefix.Length > 0) { serializationMember = (SerializationMemberInfo)elementMembersMap[state.Parameters.Namespaces.GetNamespace(reader.Prefix) + (char)0xff + reader.LocalName]; } else { serializationMember = (SerializationMemberInfo)elementMembersMap[reader.LocalName]; } if (serializationMember == null) { XmlReaderHelper.ReadAndConsumeMatchingEndElement(reader); } else { state.PushCurrentMemberInfo(serializationMember); try { if (serializationMember.SerializeAsValueNodeAttributeName != null && serializationMember.GetSerializer(reader) is TypeSerializerWithSimpleTextSupport) { var s = reader.GetAttribute(serializationMember.SerializeAsValueNodeAttributeName); var serializer = serializationMember.GetSerializer(reader); serializationMember.SetValue(obj, ((TypeSerializerWithSimpleTextSupport)(serializer)).Deserialize(s, state)); XmlReaderHelper.ReadAndConsumeMatchingEndElement(reader); } else { serializationMember.SetValue(obj, serializationMember.GetSerializer(reader).Deserialize(reader, state)); } } finally { state.PopCurrentMemberInfo(); } } }
protected virtual void DeserializeAttribute(object obj, XmlReader reader, SerializationContext state) { object value; SerializationMemberInfo serializationMember; if (reader.Prefix == "xmlns") { return; } if (reader.Prefix.Length > 0) { serializationMember = (SerializationMemberInfo)attributeMembersMap[state.Parameters.Namespaces.GetNamespace(reader.Prefix) + (char)0xff + reader.LocalName]; } else { serializationMember = (SerializationMemberInfo)attributeMembersMap[reader.Name]; } if (serializationMember == null) { if (obj is ISerializationUnhandledMarkupListener) { ((ISerializationUnhandledMarkupListener)obj).UnhandledAttribute(reader.Name, reader.Value); } return; } state.PushCurrentMemberInfo(serializationMember); try { value = serializationMember.GetSerializer(reader).Deserialize(reader, state); } finally { state.PopCurrentMemberInfo(); } serializationMember.SetValue(obj, value); }