IDesign C#编码规范(之七)

编码|规范

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;
}

时间: 2025-01-19 20:12:26

IDesign C#编码规范(之七)的相关文章

IDesign C#编码规范(之三)

编码|规范 续之二,IDesign C#编码规范之三. 34. 避免使用new继承修饰符,而是使用override. Avoid using the new inheritance qualifier. Use override instead. 35. 对非密封类总是将public和protected方法标记为virtual. Always mark public and protected methods as virtual in a non sealed class. 36. 除非涉及到

IDesign C#编码规范(总结)

编码|规范 5资源 Resource5.1 Programming .NET Components By Juval Lowy, O'Reilly 2003 ISBN: 05960034715.2 The .NET Master Class Authored by Juval Lowy, this world acclaimed intense class covers everything, from .NET essentials to the application frameworks

IDesign C#编码规范(之五)

编码|规范 续四,休息天翻得很少,不过总算在keep doing,:-) 4 Framework特别指导 Framework Specific Guidelines 4.1 数据访问 Data Access 1. 总是使用类型安全的数据集或者数据表.避免使用原始的ADO.NET. Always use type-safe data sets or data tables . Avoid raw ADO.NET. 2. 访问数据库时总是使用事务. Always use transactions w

IDesign C#编码规范(之九)

编码|规范 4.5远程操作 Remoting1.宁可使用管理配置(配置文件)而不使用程序自动配置.Prefer administrator configuration to programmatic configation.2.总是在单独调用对象里完成IDisposable.Always implement IDisposable on single call objects.3.远程操作时总是选用TCP信道和二进制格式Always prefer TCP channel and binary f

IDesign C#编码规范(之十)

编码|规范 4.6安全 Security1.总是使用强名称发布代码,该名称对于该应用程序而言是私有的,对于你是公有的.Always demand your own strong name on assemblies and components that are private to the application, but are public(so that only you use them).public class PublicKeys{public const string MyCo

IDesign C#编码规范(之十一)

编码|规范 4.7企业服务Enterprise Service1.在事务方法里不要捕捉异常.要用AutoComplete属性.Do not catch exceptions in a transactional method. Use the AutoComplete attribute.a) See Chapter 4 in COM and .NET Component Services.2.不要调用SetComplete(), SetAbort(),以及相关方法.要用AutoComplete

IDesign C#编码规范(之六)

编码|规范 大家中秋好,首先非常感谢xiaxia翻译的资料.由于我对这个文档也是兴趣浓厚,所以就把下面的部分给翻译了.希望大家多多指教. 4.2ASP.NET and Web Services1.避免将代码放入ASP.NET的ASPX文件中. 所有的代码都应该放在相关代码的Partial类中.Avoid putting code in ASPX files of ASP.NET. All code should be in the code beside partial class.2.放在相关

IDesign C#编码规范(之八)

编码|规范 4.4多线程 Multithreading1.应用同步机制空间.Use Synchronization Domains. See Chapter 8 in Programming .NET Components.避免手工的同步机制,应为这样容易导致死锁和竞态条件.a) Avoid manual synchronization because that often leads to deadlocks and race conditions.2.永远不要在外部调用你的同步机制空间.Ne

IDesign C#编程规范(二)

编程|规范 续之一,小鸡射手接着翻译了IDesign编码规范的第二章前部. 2 编码惯例 Coding Practices 1. 避免在一个文件中放多个类. Avoid putting multiple classes in a single file. 2. 一个文件应该只对一个命名空间提供类型.避免在同一文件中有多个命名空间. A single file should only contribute types to a single namespace. Avoid having mult