Support for ShouldSerialize ?

Apr 23, 2010 at 8:52 AM


It seems that Xsd2Code had no support for ShouldSerialize pattern.     I'm wrong?

ShouldSerialize is very useful when using nullable. A small example:  

    public class Person
        public int ID;
        public String Nome;
        public DateTime BirthDate;
        public int? Counter;

        public bool ShouldSerializeCounter() { return Counter.HasValue; }

If I use ShouldSerialize the serizalized xml is:

<?xml version="1.0" encoding="utf-16"?>
<Person xmlns:xsi="" xmlns:xsd="">

If I NOT use ShouldSerialize xml is:

<?xml version="1.0" encoding="utf-16"?><Person xmlns:xsi="" xmlns:xsd="">
<Counter xsi:nil="true" />

I don't want <Counter> tag if the value is null.

Is there another way to get that using Xsd2Code without support for ShouldSerialize?


  thank you