上一篇:IDesign C#编码规范(总结) >>
IDesign C#编码规范(之十一)
1. 在事务方法里不要捕捉异常。要用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属性。
Do not call SetComplete(), SetAbort(), and the like. Use the AutoComplete attribute.
[Transaction]
public class MyComponent : ServicedComponent
{
[AutoComplete]
public void MyMethod(long objectIdentifier)
{
GetState(objectIdentifier);
DoWork();
SaveState(objectIdentifier);
}
}
3. 总是覆写CanBePooled方法并且返回true(除非你有更好的原因不用返回值到池)。
Always override CanBePooled and return true(unless you have a good reason not to return to pool).
Public class MyComponent : ServicedComponent
{
protected override bool CanBePooled()
{
return true;
}
}
4. 总是在对象池里显示地调用Dispose(),除非该组件已被配置为使用JITA。
Always call Dispose() explicitly on a pooled objects unless the component is configured to use JITA as well.
5. 当组建使用JITA时不可调用Dispose()。
Never call Dispose() when the components uses JITA.
6. 总是为应用程序和组件设置权限水平。
Always set authorization level to application and component.
7. 将所有应用程序的检证水平设置为私有。
Set authentication level to privacy on all applications.
[assembly: ApplicationActivation(ActivationOption.Server)]
[assembly: ApplicationAccessControl(
true, //Authorization
AccessChecksLevel = AccessChecksLevelOption.ApplicationComponent,
Authentication = AuthenticationOption.Privacy,
ImpersonationLevel = ImpersonationLevelOption.Identify)]
8. 将客户端程序集的角色水平设置为Identity。
Set impersonation level on client assemblies to Identity.
9. 总是将可服务组件的ComponentAccessControl属性设置为true。
Always set ComponentAccessControl attribute on serviced components to true.
a) The default is true
[ComponentAccessControl]
public class MyComponent : ServicedComponent
{…}
10. 总是将每一个用户角色设置为marshaler。
Always add to the marshaler role the Everyone user.
[assembly: SecureRole(“Marshaler”, SetEveryoneAccess = true)]
11. 应用SecureMethod属性于所有的要求检证的类。
Apply SecureMethod attribute to all classes requiring authentication.
[SecurityMethod]
public class MyComponent : ServicedComponent
{…}
下一篇:IDesign C#编码规范(之十) >>
相关文章:
- · C#中虛函數,抽象,接口的簡單説明
- · C#软件启动设计
- · 在C#中实现打印功能(C#中PrintDialog,PrintDocument的使用)
- · C#下Socket对象的BeginReceive方法
- · [C#][正则表达式]寻找匹配的Groups的几种方法
- · C#程序员面试(一)答案
- · 使用智能设备扩展在 C# 中开发自定义控件
- · C#规范漫谈
- · Simple Image Slide Show C# edition
- · 用C#制作作屏幕捕获程序
- · 让窗体飘动起来--C#中Timer组件用法
- · C#做托盘程序
- · 三值逻辑的C#实现
- · 关于C#中的结构(下)
- · C#函数的参数中返回结构数组
- · C#异常处理机制初步
- · c#高級編程記錄--第一章
- · 关于C#中的结构
- · C#编程打造自己的IE浏览器
- · 用C#创建可拖动窗体
- · C#中的委托
- · C# variable criterion
- · C# FAQ
- · C#学习杂记
- · C#2.0的特性
- · 将控件中的数据输出保存到本地excel或word中,同时保存图片到本地(c#)
- · C#分析数据库结构,使用XSL模板自动生成代码
- · 捕捉DataGrid的双击事件(C#版本)
- · C#设计模式讨论——开篇闲话
- · C#如何取硬件标志
- · 使用C#制作《邮件特快专递》
- · 使用C#调用外部Ping命令获取网络连接情况
- · C# 编程规范
- · 教你在C#中如何读写INI文件
- · C#数组篇讲解
- · C#如何取硬件标志
- · C#语法入门1
- · 如何使用.NET生成C#源代码
