<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: XmlSerializer, Xsd.exe, Nullable&lt;T&gt; and you.</title>
	<atom:link href="http://www.ageektrapped.com/blog/xmlserializer-xsdexe-nullablet-and-you/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ageektrapped.com/blog/xmlserializer-xsdexe-nullablet-and-you/</link>
	<description>Trapped online since 2004</description>
	<lastBuildDate>Wed, 11 Jan 2012 10:22:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Gonçalo Lopes</title>
		<link>http://www.ageektrapped.com/blog/xmlserializer-xsdexe-nullablet-and-you/comment-page-1/#comment-597</link>
		<dc:creator>Gonçalo Lopes</dc:creator>
		<pubDate>Wed, 14 Jan 2009 01:07:26 +0000</pubDate>
		<guid isPermaLink="false">http://69.42.58.100/~jaso3118/blog/xmlserializer-xsdexe-nullablet-and-you/#comment-597</guid>
		<description>Hi there. I would just like to let you know that nullable types can indeed be supported if you just tweak your pattern a little bit. Consider a design like this:

class MyClass
{
    // this is the nullable value container
    private int? number;

    // A regular integer property accessor.
    // If the private nullable container is not
    // defined, it will return the default value.
    [XmlAttribute(&quot;number&quot;)]
    public int Number
    {
        get { return number != null ? number.Value : default(int); }
        set { this.number = value; }
    }

    // This boolean property uses the nullable container
    // to check whether some value has been assigned
    // XmlSerializer and Xsd.exe will use this adequately.
    public bool NumberSpecified
    {
        get { return number != null; }
    }
}


In this way you can have full nullable semantics. The public object interface still does not support &#039;int?&#039;, but the interaction is semantically equivalent, since you can simply ask whether &#039;NumberSpecified&#039; is true to know if the value has been assigned or not.

Or if you really need a nullable property, you can just expose that with a [XmlIgnore] tag.

Best regards,

Gonçalo</description>
		<content:encoded><![CDATA[<p>Hi there. I would just like to let you know that nullable types can indeed be supported if you just tweak your pattern a little bit. Consider a design like this:</p>
<p>class MyClass<br />
{<br />
    // this is the nullable value container<br />
    private int? number;</p>
<p>    // A regular integer property accessor.<br />
    // If the private nullable container is not<br />
    // defined, it will return the default value.<br />
    [XmlAttribute("number")]<br />
    public int Number<br />
    {<br />
        get { return number != null ? number.Value : default(int); }<br />
        set { this.number = value; }<br />
    }</p>
<p>    // This boolean property uses the nullable container<br />
    // to check whether some value has been assigned<br />
    // XmlSerializer and Xsd.exe will use this adequately.<br />
    public bool NumberSpecified<br />
    {<br />
        get { return number != null; }<br />
    }<br />
}</p>
<p>In this way you can have full nullable semantics. The public object interface still does not support &#8216;int?&#8217;, but the interaction is semantically equivalent, since you can simply ask whether &#8216;NumberSpecified&#8217; is true to know if the value has been assigned or not.</p>
<p>Or if you really need a nullable property, you can just expose that with a [XmlIgnore] tag.</p>
<p>Best regards,</p>
<p>Gonçalo</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ondrej Medek</title>
		<link>http://www.ageektrapped.com/blog/xmlserializer-xsdexe-nullablet-and-you/comment-page-1/#comment-513</link>
		<dc:creator>Ondrej Medek</dc:creator>
		<pubDate>Sun, 14 Sep 2008 16:37:08 +0000</pubDate>
		<guid isPermaLink="false">http://69.42.58.100/~jaso3118/blog/xmlserializer-xsdexe-nullablet-and-you/#comment-513</guid>
		<description>Hi, what about something like this (.NET 2.0)?

        /// 
        /// Latitude.
        /// 
        [XmlAttribute]
        public double Lat
        {
            get { return (double)lat; }
            set { lat = value; }
        }


        public bool LatSpecified
        {
            get { return lat.HasValue; }
        }</description>
		<content:encoded><![CDATA[<p>Hi, what about something like this (.NET 2.0)?</p>
<p>        ///<br />
        /// Latitude.<br />
        ///<br />
        [XmlAttribute]<br />
        public double Lat<br />
        {<br />
            get { return (double)lat; }<br />
            set { lat = value; }<br />
        }</p>
<p>        public bool LatSpecified<br />
        {<br />
            get { return lat.HasValue; }<br />
        }</p>
]]></content:encoded>
	</item>
</channel>
</rss>

