神奇的名字燮preSS的空List XmlSerialization神奇、名字、preSS、List

2023-09-03 16:35:33 作者:负剑遠行游

由于正确的MagicName(这是类似CanSerialize),下面的code将燮preSS XML为空列表。

那是什么神奇的名字?

 公共类MyClass的{
    公开名单< INT> MYLIST {获得;组; }
    公共BOOL MyListMagicName(){返回MyList.Count!= 0; }
    公共MyClass的(){MYLIST =新的名单,其中,INT>(); }
}
 

解决方案

我的事情,你指的是 ShouldSerialize *属性名* 方法的命名规则,但AFAIK这并不参考XML序列化,但在Windows窗体组件属性序列化(我可能是错的呢)。在这里看到:http://msdn.microsoft.com/en-us/library/53b8022e%28VS.71%29.aspx

更新。它似乎也适用于XML序列化,但它是一个未公开的特性:http://horacegoescoding.blogspot.com/2009/04/using-shouldserialize-for-conditional.html

Given the correct "MagicName" (it was something like "CanSerialize"), the following code would suppress xml for empty lists.

fgo科普神器的起名变色代码 让你的名字变得炫彩十足

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