Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>slugster,</p> <p>You may want to consider switching over to XMLSerializer instead. Here is what I have determined over time:</p> <p>The XMLSerializer and DataContractSerializer classes provides a simple means of serializing and deserializing object graphs to and from XML.<br/> <br/> The key differences are:<br/> 1.<br/> XMLSerializer has much smaller payload than DCS if you use [XmlAttribute] instead of [XmlElement]<br/> DCS always store values as elements<br/> 2.<br/> DCS is "opt-in" rather than "opt-out"<br/> With DCS you explicitly mark what you want to serialize with [DataMember]<br/> With DCS you can serialize any field or property, even if they are marked protected or private<br/> With DCS you can use [IgnoreDataMember] to have the serializer ignore certain properties<br/> With XMLSerializer public properties are serialized, and need setters to be deserialized<br/> With XmlSerializer you can use [XmlIgnore] to have the serializer ignore public properties<br/> 3.<br/> BE AWARE! DCS.ReadObject DOES NOT call constructors during deserialization<br/> If you need to perform initialization, DCS supports the following callback hooks:<br/> [OnDeserializing], [OnDeserialized], [OnSerializing], [OnSerialized]<br/> (also useful for handling versioning issues)<br/> <br/> If you want the ability to switch between the two serializers, you can use both sets of attributes simultaneously, as in:<br/></p> <pre><code>[DataContract] [XmlRoot] public class ProfilePerson : NotifyPropertyChanges { [XmlAttribute] [DataMember] public string FirstName { get { return m_FirstName; } set { SetProperty(ref m_FirstName, value); } } private string m_FirstName; [XmlElement] [DataMember] public PersonLocation Location { get { return m_Location; } set { SetProperty(ref m_Location, value); } } private PersonLocation m_Location = new PersonLocation(); // Should change over time [XmlIgnore] [IgnoreDataMember] public Profile ParentProfile { get { return m_ParentProfile; } set { SetProperty(ref m_ParentProfile, value); } } private Profile m_ParentProfile = null; public ProfilePerson() { } } </code></pre> <p>Also, check out my Serializer class that can switch between the two:</p> <pre><code>using System; using System.IO; using System.Runtime.Serialization; using System.Text; using System.Xml; using System.Xml.Serialization; namespace ClassLibrary { // Instantiate this class to serialize objects using either XmlSerializer or DataContractSerializer internal class Serializer { private readonly bool m_bDCS; internal Serializer(bool bDCS) { m_bDCS = bDCS; } internal TT Deserialize&lt;TT&gt;(string input) { MemoryStream stream = new MemoryStream(input.ToByteArray()); if (m_bDCS) { DataContractSerializer dc = new DataContractSerializer(typeof(TT)); return (TT)dc.ReadObject(stream); } else { XmlSerializer xs = new XmlSerializer(typeof(TT)); return (TT)xs.Deserialize(stream); } } internal string Serialize&lt;TT&gt;(object obj) { MemoryStream stream = new MemoryStream(); if (m_bDCS) { DataContractSerializer dc = new DataContractSerializer(typeof(TT)); dc.WriteObject(stream, obj); } else { XmlSerializer xs = new XmlSerializer(typeof(TT)); xs.Serialize(stream, obj); } // be aware that the Unicode Byte-Order Mark will be at the front of the string return stream.ToArray().ToUtfString(); } internal string SerializeToString&lt;TT&gt;(object obj) { StringBuilder builder = new StringBuilder(); XmlWriter xmlWriter = XmlWriter.Create(builder); if (m_bDCS) { DataContractSerializer dc = new DataContractSerializer(typeof(TT)); dc.WriteObject(xmlWriter, obj); } else { XmlSerializer xs = new XmlSerializer(typeof(TT)); xs.Serialize(xmlWriter, obj); } string xml = builder.ToString(); xml = RegexHelper.ReplacePattern(xml, RegexHelper.WildcardToPattern("&lt;?xml*&gt;", WildcardSearch.Anywhere), string.Empty); xml = RegexHelper.ReplacePattern(xml, RegexHelper.WildcardToPattern(" xmlns:*\"*\"", WildcardSearch.Anywhere), string.Empty); xml = xml.Replace(Environment.NewLine + " ", string.Empty); xml = xml.Replace(Environment.NewLine, string.Empty); return xml; } } } </code></pre> <p>Good Luck,<br/> Jim McCurdy</p> <p><a href="http://FaceToFaceSoftware.com" rel="nofollow noreferrer" title="Face To Face Software">Face To Face Software</a> and <a href="http://YinYangMoney.com" rel="nofollow noreferrer" title="YinYangMoney">YinYangMoney</a></p>
    singulars
    1. This table or related slice is empty.
    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