0

I want to serialise a object with a DateTime property

If the property is not initialized so I have :

<DateTime>0001-01-01T00:00:00</DateTime>

But if I use a DateTime? type I have :

<DateTime d4p1:nil="true" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance" />

I want this property will not be serialized if it is null or uninitialized.

How to do ?

1 Answers1

1

If you are using XmlSerializer, you should add a property called ShouldSerializeYourProperty and return yourDateTime.HasValue

Xml serialization - Hide null values

Community
  • 1
  • 1
jimbobmcgee
  • 1,561
  • 11
  • 34