7
鑑於正確的「MagicName」(它類似於「CanSerialize」),下面的代碼將爲空列表壓制xml。禁止Xml序列化的空列表
那是什麼神奇的名字?你指的是ShouldSerialize*PropertyName*
方法命名約定,但據我所知,這並非指到XML序列化,但在Windows窗體組件屬性系列化
public class MyClass {
public List<int> MyList{ get; set; }
public bool MyListMagicName() { return MyList.Count != 0; }
public MyClass() { MyList = new List<int>(); }
}
Markdown評論:我希望「ShouldSerialize」部分爲粗體,「PropertyName」部分爲粗體和斜體,不包圍星號。有趣的是,在編輯模式下顯示的預覽窗口顯示了預期的格式! – Konamiman 2009-10-21 10:24:29
另請參閱:http://www.devolutions.net/articles/serialization.aspx#S222 – 2009-10-21 10:24:34