I'm trying to control serialization in a class that contains a couple ints,
some strings, and a date.  At times, each of these elements may be left
uninitialized.  When serialized to xml, the uninitialized ints and strings
are simply not serialized.  For example, using the following class fragment,
if Agency is left blank but the int and the date have values, the class is
serialized without it:
<Class GroupID="1" RefDate="1/1/2004 14:54:33" />

However, if the date is not initialized, it shows up anyway, as in:
<Class Agency="WSOC" GroupID="1" RefDate="0001-01-01T00:00:00.0000000-08:00"
/>

We'd really rather the RefDate attribute not show up at all if the date is
uninitialized, but I cannot find any options to accomplish this.

Anyone know how to do this?

Mike

The class:

[XmlAttribute]
public string Agency
{
        get{return _agency;}
        set{_agency = value;}
}

[XmlAttribute]
public int GroupID
{
        get{return _groupID;}
        set{_groupID = value;}
}

[XmlAttribute]
public DateTime RefDate
{
        get{return _refDate;}
        set{_refDate = value;}
}

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to