/// <summary> /// Reads the XML stream or document with an <see cref="T:System.Xml.XmlDictionaryReader" /> and returns the deserialized object; it also enables you to specify whether the serializer can read the data before attempting to read it. /// </summary> /// <param name="reader">An <see cref="T:System.Xml.XmlDictionaryReader" /> used to read the XML document.</param> /// <param name="verifyObjectName">true to check whether the enclosing XML element name and namespace correspond to the root name and root namespace; otherwise, false to skip the verification.</param> /// <returns> /// The deserialized object. /// </returns> public override object ReadObject(XmlDictionaryReader reader, bool verifyObjectName) { Argument.IsNotNull("reader", reader); var memoryStream = new MemoryStream(reader.ReadElementContentAsBase64()); return(BinarySerializerHelper.DiscoverAndDeSerialize(memoryStream, _type)); }
/// <summary> /// Writes only the content of the object to the XML document or stream using the specified <see cref="T:System.Xml.XmlDictionaryWriter" />. /// </summary> /// <param name="writer">An <see cref="T:System.Xml.XmlDictionaryWriter" /> used to write the XML document or stream.</param> /// <param name="graph">The object that contains the content to write.</param> public override void WriteObjectContent(XmlDictionaryWriter writer, object graph) { Argument.IsNotNull("writer", writer); var memoryStream = new MemoryStream(); BinarySerializerHelper.DiscoverAndSerialize(memoryStream, graph, _type); var bytes = memoryStream.ToByteArray(); writer.WriteBase64(bytes, 0, bytes.Length); }