• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

BestpacticesindevelopingASP.NETapplications

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

在 codeproject上面看到的文章,转一下


Best pactices in developing ASP.NET applications...

1. Remove unused private fields and functions.
2. Do not cast unnecessarily. Avoid duplicate casts where possible, since there is a cost associated with them.
3. Properties that return arrays are prone to code inefficiencies. Consider using a collection or making this a method.
4. To test for empty strings, check if String.Length is equal to zero. Constructs such as "".Equals(someString) andString.Empty.Equals(someString) are less efficient than testing the string length. Replace these with checks forsomeString.Length == 0.
5. Methods in the same type that differ only by return type can be difficult for developers and tools to properly recognize. When extending a type, be sure not to define new methods that differ from base type methods only by type.
6. Use stringbuilder instead of string types for string manipulation. 
7. Use String.Format instead of concatenating and appending strings.
8. Use Type.TryParse rather than Convert.ToDestinationType(). For example, use int.TryParse() rather thanConvert.ToInt32() which might throw an exception.
9. Override Equals() method wherever applicable in your classes.
10. Consider passing base types as parameters - Using base types as parameters to methods improves re-use of these methods if you only use methods & properties from the parameter's base class. E.g. use Stream instead of FileStream as a parameter when only calling Stream.Read(), this makes the method work on all kind of streams instead of just File streams.
11. Do not catch general exception types - You should not catch Exception or SystemException. Catching generic exception types can hide run-time problems from the library user, and can complicate debugging. You should catch only those exceptions that you can handle gracefully.
12. Use properties instead of visible instance fields.
13. Follow the same naming conventions accross the solution. 
14. Remove unwanted commented code, indent code properly.
15. Use curly braces with in an if statement, even if there is a single statement in the if block. This will provide better readability.
16. Make sure to refactor your code to move the duplicated code to common reusable functions.
17. Move one time control settings into the .aspx page rather than having them in the code behind in if(!IsPostback) block.
18. Use inheritance wherever possible, which enables code reuse and also reduces the amount of code we have to write and test.
19. Move the reusable JavaScript functions to an external .js file instead of having them on the page.
20. For controls that are declarativley specified on the page, tie the event handlers to the controls events on the aspx page rather than initializing them in the codebehind. If the controls are built dynamically, then we do not have a choice.
21. Make sure to check for nulls when using any type retrieved from a session, querystring or a database to avoidNullReferenceExceptions.
22. Use foreach loop instead of using for loop which may lead to out of boundary run time exceptions.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
一个简单的ASP.NETMVC下的权限方案发布时间:2022-07-10
下一篇:
查看服务器运行多少个ASP.NET Core程序发布时间:2022-07-10
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap