Given the correct "MagicName" (it was something like "CanSerialize"), the following code would suppress xml for empty lists.
What was that magic name?
public class MyClass {
public List<int> MyList{ get; set; }
public bool MyListMagicName() { return MyList.Count != 0; }
public MyClass() { MyList = new List<int>(); }
}
I thing you are referring to the ShouldSerialize*PropertyName*
method naming convention, but AFAIK this does not refer to XML serialization but to component properties serialization in Windows Forms (I may be wrong anyway). See here: http://msdn.microsoft.com/en-us/library/53b8022e%28VS.71%29.aspx
UPDATE. It seems that it also works for XML serialization, but it is an undocumented feature: http://horacegoescoding.blogspot.com/2009/04/using-shouldserialize-for-conditional.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With