magic name to suppress XmlSerialization of an empty List
Given the correct "Ma开发者_如何转开发gicName" (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
精彩评论