1

Assume I have a class like this:

[Serializable]
public class Person
{
  public string Name { get; set; }
  public int Age { get; set; }
  public bool Deleted { get; set; }
}

I would like the output to be:

<Person>
<Name>Thomas</Name>
<Age>33</Age>
<Deleted />
</Person>

or

<Person>
<Name>Thomas</Name>
<Age>33</Age>
</Person>

Depending on the setting of .Deleted = true|false.

Thomas Kjørnes
  • 1,928
  • 1
  • 17
  • 17

1 Answers1

1

Check out this answer...

Basically, you want to use the XmlSerializer ShouldSerialize. Note that in this case, you'll probably end up with a true tag, instead of just the presence of the tag; you might have to do some more workaround if that's not good.

Community
  • 1
  • 1
Paul Sonier
  • 38,903
  • 3
  • 77
  • 117