Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

magic name to suppress XmlSerialization of an empty List

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>(); }
}
like image 362
Forgetful Avatar asked Oct 21 '09 10:10

Forgetful


1 Answers

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

like image 182
Konamiman Avatar answered Nov 11 '22 21:11

Konamiman