Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is XmlSerializer so hard to use?
    primarykey
    data
    text
    <p>I imagine to use XML serialization like this:</p> <pre><code>class Foo { public Foo (string name) { Name1 = name; Name2 = name; } [XmlInclude] public string Name1 { get; private set; } [XmlInclude] private string Name2; } StreamWriter wr = new StreamWriter("path.xml"); new XmlSerializer&lt;Foo&gt;().Serialize (wr, new Foo ("me")); </code></pre> <p><b>Edit:</b> I know this code is wrong. It was just to display how I would like to use it.</p> <p>But this does not work at all:</p> <ul> <li>XmlSerializer is not generic. I have to cast from and to object on (de)serialization.</li> <li>Every property has to be fully public. Why aren't we just using Reflection to access private setters?</li> <li>Private fields cannot be serialized. I'd like to decorate private fields with an attribute to have XmlSerializer include them.</li> </ul> <p>Did I miss something and XmlSerializer is actually offering the described possibilities? Are there alternate serializers to XML that handle these cases more sophisticatedly?</p> <p>If not: We're in 2010 after all, and .NET has been around for many years. XML serialization is often used, totally standard and should be really easy to perform. Or is my understanding possibly wrong and XML serialization ought not to expose the described features for a good reason?</p> <p><b>Edit:</b> Legacy is not a good reason imo. <code>List</code>was nongeneric at first, too.</p> <p>(Feel free to adjust caption or tags. If this should be CW, please just drop a note.)</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.
 

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