G
Guest
I can't get a TimeSpan to serialize properly to XML, despite the fact
that the documentation says that it is serializable. This class:
public class MyClass
{
TimeSpan _TimeSpan = new TimeSpan(1,2,3,4);
public TimeSpan ATimeSpan
{
get { return _TimeSpan; }
set { _TimeSpan = value; }
}
public int AnInt
{
get { return 99; }
set { }
}
}
should be serialized with this code:
MyClass myClass = new MyClass();
XmlSerializer serializer = new XmlSerializer(typeof(MyClass));
StringWriter writer = new StringWriter();
serializer.Serialize(writer,myClass);
writer.Close();
textBox1.Text = writer.GetStringBuilder().ToString();
but the timespan object is empty:
<?xml version="1.0" encoding="utf-16"?>
<MyClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ATimeSpan />
<AnInt>99</AnInt>
</MyClass>
Am I doing something obviously stupid?
that the documentation says that it is serializable. This class:
public class MyClass
{
TimeSpan _TimeSpan = new TimeSpan(1,2,3,4);
public TimeSpan ATimeSpan
{
get { return _TimeSpan; }
set { _TimeSpan = value; }
}
public int AnInt
{
get { return 99; }
set { }
}
}
should be serialized with this code:
MyClass myClass = new MyClass();
XmlSerializer serializer = new XmlSerializer(typeof(MyClass));
StringWriter writer = new StringWriter();
serializer.Serialize(writer,myClass);
writer.Close();
textBox1.Text = writer.GetStringBuilder().ToString();
but the timespan object is empty:
<?xml version="1.0" encoding="utf-16"?>
<MyClass xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ATimeSpan />
<AnInt>99</AnInt>
</MyClass>
Am I doing something obviously stupid?