Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Why is it important to distinguish between a string containing '\r\n' and an empty string? In general, when using data contract serialization you don't care about the XML format/structure or how it stores the data as long as it "round-trips" correctly.</p> <p>This is how we use it:</p> <pre><code>DataContractSerializer serializer = CreateSerializer(this.GetType()); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; using (XmlWriter writer = XmlTextWriter.Create(sb, settings)) { serializer.WriteObject(writer, this); writer.Flush(); } internal static T Deserialize&lt;T&gt;(Stream stream) { DataContractSerializer serializer = CreateSerializer(typeof(T)); return (T)serializer.ReadObject(stream); } public static DataContractSerializer CreateSerializer(Type type) { DataContractSerializer serializer = new DataContractSerializer(); return serializer; } </code></pre> <p>If I'm not mistaken, characters like linefeeds are not allowable characters within an XML value and would need to be either encoded or contrained in a CDATA section. The data contract serializer does neither of these. Tools like XML Notepad are changing the data because they realize these aren't legal characters and removing them to create conformant XML.</p> <p>It actually shouldn't be surprising that string data can be returned differently between a binary serializer and an XML serializer. The binary serializer will serialize the exact binary representation of the data bit for bit and has no "rules" on what are legal characters, etc.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload