编码|规范4.3序列化 Serialization
1.总是标记未封装的类为[Serializable]
Always mark non-sealed classes as serializable.
2.总是标记未序列化的成员变量为[non-serializable]
Always mark un-serializable member variables as non-serializable.
3.总是标记序列化类中的委托为[NonSerialized]
Always mark delegates on a serialized class as non- serializable fields.
[Serializable]
public class MyClass
{
[field: NonSerialized]
public event EventHandler MyEvent;
}
IDesign C#编码规范(之七)
80酷酷网 80kuku.com