There’s a lot of information (including sample routines) on how to serialize/deserialize objects in C#. Hunt down a couple of routines that accept generic types and add them to your personal utility class and reuse them forever. Be aware, however, that there’s an issue with serializing nullable types. Basically it can’t be done if an object’s property is marked with an XmlAttribute. You will need to mark the property as an XmlElement.
[XmlElement(IsNullable=true)] public DateTime? MachineDateChange { get ; set ; }
And use some caution as the property datatype must match the IsNullable setting for the XmlElement markup. Believe it or not, the following “type mismatch” will throw an exception when serializing since MachineDateChange, in the following case, isn’t actually nullable like it is above:
[XmlElement(IsNullable = true)] public DateTime MachineDateChange { get; set; }
Here are a couple of good resources:
Thats great, however the XML serializer still emits the element with xsi:nil=”true”. Any idea how to supress it, if it is null.
Thanks
I wanna know too!!!
@Lee @Matheus – So, the problem is with value types only since null reference types and strings are suppressed by default. The solution, in my opinion is totally obscure, but, believe it or not there’s a pattern to check if null and suppress as described here on StackOverflow: http://stackoverflow.com/quest.....serializer
My coder is trying to convince me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about a year and am anxious about switching to another platform. I have heard fantastic things about blogengine.net. Is there a way I can import all my wordpress posts into it? Any kind of help would be greatly appreciated!
Bon alors c’est qui le super kadorseo?
Wonderful work! This is the type of information that should be shared around the net. Shame on Google for not positioning this post higher! Come on over and visit my web site . Thanks =)