<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Luminis Software Development &#187; mac os x</title>
	<atom:link href="http://lsd.luminis.eu/tag/mac-os-x/feed/" rel="self" type="application/rss+xml" />
	<link>http://lsd.luminis.eu</link>
	<description></description>
	<lastBuildDate>Wed, 28 Dec 2011 20:44:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>nl</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Being a .NET developer in a Mac OSX world: serializing XmlDates</title>
		<link>http://lsd.luminis.eu/being-a-net-developer-in-a-mac-osx-world-serializing-xmldates/</link>
		<comments>http://lsd.luminis.eu/being-a-net-developer-in-a-mac-osx-world-serializing-xmldates/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 11:39:43 +0000</pubDate>
		<dc:creator>Richard de Zwart</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[mac os x]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[MonoDevelop]]></category>

		<guid isPermaLink="false">http://lsd.luminis.nl/?p=1099</guid>
		<description><![CDATA[I blogged before on differences in implementation between the Mono and the Microsoft implementation of the .NET framework. In this post I investigate a difference in XmlSerialization.
Dates in XSD
When you write an XSD you have (at least) 3 options to use dates and/or times:

xsd:date
xsd:dateTime
xsd:time

Most of the time you probably choose the &#8220;dateTime&#8221;, since that maps [...]]]></description>
			<content:encoded><![CDATA[<p>I blogged before on <a href="http://lsd.luminis.nl/being-a-net-developer-in-a-mac-osx-world-storing-null-values-in-a-database/" target="_blank">differences in implementation</a> between the Mono and the Microsoft implementation of the .NET framework. In this post I investigate a difference in XmlSerialization.</p>
<h3>Dates in XSD</h3>
<p>When you write an XSD you have (at least) 3 options to use dates and/or times:</p>
<ul>
<li><a href="http://www.w3.org/TR/xmlschema-2/#date" target="_blank">xsd:date</a></li>
<li><a href="http://www.w3.org/TR/xmlschema-2/#dateTime" target="_blank">xsd:dateTime</a></li>
<li><a href="http://www.w3.org/TR/xmlschema-2/#time" target="_blank">xsd:time</a></li>
</ul>
<p>Most of the time you probably choose the &#8220;dateTime&#8221;, since that maps nicely to the DateTime type in .NET. But you might choose &#8220;date&#8221; for a birthday for example, and you might even choose &#8220;time&#8221; for uh, well for a time of some sort&#8230;</p>
<p>For his post I&#8217;ll use the following XSD. It&#8217;s a bit contrived but I like this better than &#8220;MyDate&#8221; and &#8220;ADateTimeField&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:schema</span> <span style="color: #000066;">xmlns:xsd</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2001/XMLSchema&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Book&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;BookType&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/xsd:element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:complexType</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;BookType&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Title&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:string&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;Price&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:float&quot;</span> <span style="color: #000066;">nillable</span>=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;PrintedAt&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:date&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;SoldAt&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:dateTime&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;WillReadTodayAt&quot;</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">&quot;xsd:time&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:sequence<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:complexType<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsd:schema<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<h3>Generate classes from your XSD</h3>
<p>Both Mono and Microsoft have command-line tools that generate classes from your XSD. Very convenient and a good thing to do when you need simple entities. We did this in a project where we had both C# and Java code. On both sides we generated the classes from the same XSD.</p>
<p>The syntax of both tools is more or less the same:</p>
<pre>xsd book.xsd /classes /namespace:BookStore.Books</pre>
<p>will work on both systems.<br />
The outcome of both generators is quite different. The Mono version uses public fields, the MS version use properties with back-up private fields. They both adorn the fields/properties with attributes from the XmlSerialization namespace.<br />
For Microsoft it looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> BookStore.<span style="color: #0000FF;">Books</span> <span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Xml.Serialization</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">CodeDom</span>.<span style="color: #0000FF;">Compiler</span></span>.<span style="color: #0000FF;">GeneratedCodeAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;xsd&quot;</span>, <span style="color: #666666;">&quot;2.0.50727.42&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">SerializableAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Diagnostics</span></span>.<span style="color: #0000FF;">DebuggerStepThroughAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span>.<span style="color: #0000FF;">DesignerCategoryAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;code&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlRootAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Book&quot;</span>, <span style="color: #0600FF;">Namespace</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;&quot;</span>, IsNullable<span style="color: #008000;">=</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> BookType <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #FF0000;">string</span> titleField<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Nullable</span> priceField<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">DateTime</span> printedAtField<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">DateTime</span> soldAtField<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">DateTime</span> willReadTodayAtField<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlElementAttribute</span><span style="color: #000000;">&#40;</span>Form<span style="color: #008000;">=</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span>.<span style="color: #0000FF;">Schema</span>.<span style="color: #0000FF;">XmlSchemaForm</span>.<span style="color: #0000FF;">Unqualified</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Title <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">titleField</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">titleField</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlElementAttribute</span><span style="color: #000000;">&#40;</span>Form<span style="color: #008000;">=</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span>.<span style="color: #0000FF;">Schema</span>.<span style="color: #0000FF;">XmlSchemaForm</span>.<span style="color: #0000FF;">Unqualified</span>, IsNullable<span style="color: #008000;">=</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Nullable</span> Price <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">priceField</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">priceField</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlElementAttribute</span><span style="color: #000000;">&#40;</span>Form<span style="color: #008000;">=</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span>.<span style="color: #0000FF;">Schema</span>.<span style="color: #0000FF;">XmlSchemaForm</span>.<span style="color: #0000FF;">Unqualified</span>, DataType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;date&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">DateTime</span> PrintedAt <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">printedAtField</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">printedAtField</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlElementAttribute</span><span style="color: #000000;">&#40;</span>Form<span style="color: #008000;">=</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span>.<span style="color: #0000FF;">Schema</span>.<span style="color: #0000FF;">XmlSchemaForm</span>.<span style="color: #0000FF;">Unqualified</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">DateTime</span> SoldAt <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">soldAtField</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">soldAtField</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlElementAttribute</span><span style="color: #000000;">&#40;</span>Form<span style="color: #008000;">=</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span></span>.<span style="color: #0000FF;">Schema</span>.<span style="color: #0000FF;">XmlSchemaForm</span>.<span style="color: #0000FF;">Unqualified</span>, DataType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;time&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">DateTime</span> WillReadTodayAt <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">willReadTodayAtField</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">willReadTodayAtField</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>That could have been a bit more readable by removing all the fully-qualified namespaces (since there is a &#8220;using&#8221; at the top), the empty comments and the back-up fields (if you generate for .NET after version 3).</p>
<p>For Mono it is like this:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> BookStore.<span style="color: #0000FF;">Books</span> <span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlRootAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Book&quot;</span>, <span style="color: #0600FF;">Namespace</span><span style="color: #008000;">=</span><span style="color: #666666;">&quot;&quot;</span>, IsNullable<span style="color: #008000;">=</span><span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> BookType <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Title<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlElementAttribute</span><span style="color: #000000;">&#40;</span>IsNullable<span style="color: #008000;">=</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Single</span> Price<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlElementAttribute</span><span style="color: #000000;">&#40;</span>DataType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;date&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">DateTime</span> PrintedAt<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">public</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">DateTime</span> SoldAt<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Xml</span>.<span style="color: #0000FF;">Serialization</span></span>.<span style="color: #0000FF;">XmlElementAttribute</span><span style="color: #000000;">&#40;</span>DataType<span style="color: #008000;">=</span><span style="color: #666666;">&quot;time&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">DateTime</span> WillReadTodayAt<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Much more concise. But with an important omission: the Price has the right XmlAttribute, but should have been defined as &#8220;Nullable&#8221;. I&#8217;ve seen some remarks on this in the mailing-list/forum for Mono, but could not find out if this was already fixed. So I use the Microsoft XSD.exe whenever my XSD changes, copy paste the result to my MonoDevelop environment and recompile. I would rather call the MonoXSD on the background whenever my XSD changes (has anyone used scripts as Custom Tools in MonoDevelop?)  so that the class gets re-generated automatically. Maybe the upcoming <a href="http://www.mono-project.com/Roadmap#Upcoming_Releases">Mono 2.8</a> will fix it.</p>
<h3>It&#8217;s all a DateTime</h3>
<p>As you can see, all the fields are generated as DateTimes. Makes sense, since there is nothing else in the framework to hold time-related information. So what happens when you read an Xml file and serialize the Xml into a Book object?</p>
<p>Take this Xml:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>How to be a Mac Developer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PrintedAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1965-02-16<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PrintedAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SoldAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1965-02-16<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SoldAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;WillReadTodayAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>11:00:01<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/WillReadTodayAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And process it with this code:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">    <span style="color: #FF0000;">class</span> MainClass
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #0600FF;">void</span> Main <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> args<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> bookXml <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;
            &lt;Book&gt;
                &lt;Title&gt;How to be a Mac Developer&lt;/Title&gt;
                &lt;PrintedAt&gt;1965-02-16&lt;/PrintedAt&gt;
                &lt;SoldAt&gt;1965-02-16&lt;/SoldAt&gt;
                &lt;WillReadTodayAt&gt;11:00:01&lt;/WillReadTodayAt&gt;
            &lt;/Book&gt;
            &quot;</span><span style="color: #008000;">;</span>
&nbsp;
            BookType book <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>BookType<span style="color: #000000;">&#41;</span> ToObject<span style="color: #000000;">&#40;</span>bookXml, <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>BookType<span style="color: #000000;">&#41;</span>, Encoding.<span style="color: #0600FF;">Default</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;PrintedAt:{0}&quot;</span>, book.<span style="color: #0000FF;">PrintedAt</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;SoldAt:{0}&quot;</span>, book.<span style="color: #0000FF;">SoldAt</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WillReadAt:{0}&quot;</span>, book.<span style="color: #0000FF;">WillReadTodayAt</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Console.<span style="color: #0000FF;">ReadLine</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">object</span> ToObject<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> xml, Type xmlObjectType, Encoding encoding<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            MemoryStream xmlStream <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MemoryStream<span style="color: #000000;">&#40;</span>encoding.<span style="color: #0000FF;">GetBytes</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            StreamReader reader <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StreamReader<span style="color: #000000;">&#40;</span>xmlStream, encoding, <span style="color: #0600FF;">false</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            XmlReaderSettings readerSettings <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlReaderSettings<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            readerSettings.<span style="color: #0000FF;">CloseInput</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
            XmlReader xmlReader <span style="color: #008000;">=</span> XmlReader.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>reader, readerSettings<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            XmlSerializer xmlSerializer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSerializer<span style="color: #000000;">&#40;</span>xmlObjectType<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> xmlSerializer.<span style="color: #0000FF;">Deserialize</span><span style="color: #000000;">&#40;</span>xmlReader<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></div></div>

<h3>Different ideas on default dates</h3>
<p>You get this output in Windows (running the exe build by MonoDevelop directly on my VMWare-WindozeXP):<br />
<a href="http://lsd.luminis.nl/wp-content/uploads/2010/09/Screen-shot-2010-09-21-at-11.26.27-AM.png"><img src="http://lsd.luminis.nl/wp-content/uploads/2010/09/Screen-shot-2010-09-21-at-11.26.27-AM.png" alt="Screen shot 2010-09-21 at 11.26.27 AM" title="Screen shot 2010-09-21 at 11.26.27 AM" width="269" height="85" class="alignnone size-full wp-image-1109" /></a></p>
<p>And this output on the Mac:<br />
<a href="http://lsd.luminis.nl/wp-content/uploads/2010/09/Screen-shot-2010-09-21-at-11.30.34-AM.png"><img src="http://lsd.luminis.nl/wp-content/uploads/2010/09/Screen-shot-2010-09-21-at-11.30.34-AM.png" alt="Screen shot 2010-09-21 at 11.30.34 AM" title="Screen shot 2010-09-21 at 11.30.34 AM" width="285" height="82" class="alignnone size-full wp-image-1111" /></a></p>
<p>Interesting difference, right? Windows sets the date part of &#8220;WillReadTodayAt&#8221; to DateTime.MinValue and Mono assumes it is today. It doesn&#8217;t matter that much, since I&#8217;m going to ignore the date-part anyway for that property.<br />
The time part of the date-olny property &#8220;PrintedAt&#8221; is set to &#8220;12:00:00AM&#8221; in Windows and &#8220;00:00:00&#8243; in Mono. Again, I&#8217;m going to ignore the time-part, but what will happen when I compare dates for equality? I prefer the Mono setting.</p>
<h3>Invalid time data</h3>
<p>Take this slightly modified Xml:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>How to be a Mac Developer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PrintedAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1965-02-16<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PrintedAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;WillReadTodayAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2010-09-21T11:00:01<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/WillReadTodayAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SoldAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1965-02-16<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SoldAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Running this on Mono result in an FormatException: <a href="http://lsd.luminis.nl/wp-content/uploads/2010/09/Screen-shot-2010-09-21-at-11.41.53-AM.png"><img src="http://lsd.luminis.nl/wp-content/uploads/2010/09/Screen-shot-2010-09-21-at-11.41.53-AM-300x208.png" alt="Screen shot 2010-09-21 at 11.41.53 AM" title="Screen shot 2010-09-21 at 11.41.53 AM" width="300" height="208" class="alignnone size-medium wp-image-1112" /></a><br />
Fair enough, the data in the xml is not a Time, it is a DateTime. So an exception makes sense.</p>
<p>Wonder what Windows will do? After you have started an instance of Visual Studio to see the error, you get this:<br />
<a href="http://lsd.luminis.nl/wp-content/uploads/2010/09/Screen-shot-2010-09-21-at-11.45.46-AM.png"><img src="http://lsd.luminis.nl/wp-content/uploads/2010/09/Screen-shot-2010-09-21-at-11.45.46-AM-300x184.png" alt="Screen shot 2010-09-21 at 11.45.46 AM" title="Screen shot 2010-09-21 at 11.45.46 AM" width="300" height="184" class="alignnone size-medium wp-image-1113" /></a></p>
<p>So both platforms agree that the data is invalid. Unfortunately the position that Windows gives us is right after the offending data, at not before as I was expecting. So it took some time (way more than an hour) to realize that the problem was not in the &#8220;SoldAt&#8221;, but in the &#8220;WillReadTodayAt&#8221; just before it. Be warned.</p>
<h3>Invalid date data</h3>
<p>Now pass in a date-with-time on the field that expects only a date:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>How to be a Mac Developer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Title<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PrintedAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1965-02-16T08:01:03<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PrintedAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;WillReadTodayAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>11:00:01<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/WillReadTodayAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SoldAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1965-02-16T09:00:02<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SoldAt<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Book<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Mono doesn&#8217;t like it. Same error as before, no indication on what line and what xml-tag, alas.<br />
Windows doesn&#8217;t like it either. Same error as before, positioned right before &#8220;WillReadTodayAt&#8221;.</p>
<h3>Conclusions</h3>
<p>There&#8217;s a big difference in the C# classes that get generated. The Mono implementation is missing the support for nullables, the MS implementation is a bit too verbose.<br />
The handling of incorrect date/time information is okay in both systems.<br />
The date-part in a xsd:time gets defaulted to &#8220;1-1-1&#8243; in MS and &#8220;today&#8221; in Mono. The time-part gets defaulted to &#8220;0:0:0&#8243; in Mono and &#8220;12:0:0AM&#8221; in MS.</p>
<p><a href='http://lsd.luminis.nl/wp-content/uploads/2010/09/XmlDateDemoForArticle.zip'>The code for this article</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.eu/being-a-net-developer-in-a-mac-osx-world-serializing-xmldates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java 6 on OSX?!</title>
		<link>http://lsd.luminis.eu/java-6-on-osx/</link>
		<comments>http://lsd.luminis.eu/java-6-on-osx/#comments</comments>
		<pubDate>Sun, 11 Nov 2007 19:20:35 +0000</pubDate>
		<dc:creator>Peter Doornbosch</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mac os x]]></category>

		<guid isPermaLink="false">http://lsd.luminis.net/?p=127</guid>
		<description><![CDATA[<img class="thumbnail" src="http://blog.luminis.nl/luminis/resource/peter/java6uprise-2.jpg">
Java developers using Mac OSX need to make their voice heard.
]]></description>
			<content:encoded><![CDATA[<p>
I haven&#8217;t been using OSX for long, only since the beginning of this year, but i very much liked it from the first moment (well, to be honest not from <em>very</em> first moment; it took a day to get used to it). It seemed to be the ideal Java development platform, but slowly it became clear that we would have to wait a while for Java 6. So we waited patiently for Leopard, but Apple let us down again.
</p>
<p>
What&#8217;s most frustrating about the whole situation, is that Apple doesn&#8217;t communicate at all about its plans with Java. In an attempt to make Apple stop ignoring the Java developer community, <a href="http://blogs.sun.com/bblfish/entry/vote_for_java6_on_leopard">this blog</a> started an action to make our voice heard. Of course, we support the 13949712720901ForOSX effort too. All we ask is that Apple is more open about a timeline for Java 6 support, or a statement that this will not happen at all (which would probably fuel initiatives to create a port of Java 6 by some other means).</p>
]]></content:encoded>
			<wfw:commentRss>http://lsd.luminis.eu/java-6-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

