Use fxcop for code check and Optimization

Source: Internet
Author: User
Tags coding standards
Some time ago I made a free test tool fxcop using Microsoft. After using it, I thought it was good and I could do some work. Code It also helps to learn coding standards and improve code execution efficiency, thus improving the overall quality of code.

This tool can be tested in: design, globalization, interoperability, naming, performance (performance Rules ), you can also add rules for testing;

The tool is still very useful and will soon be used.
Tips
1. You can customize incorrect rules. We recommend that you cancel rules such as globalizationrules and securityrules.

The problematic connection at 2: 00 can be directly connected to the Code with code problems.

3. Let's take a look at the info comment of breaking, which provides a better solution.

The modified code after check is as follows:

1 class naming rules

2. judge whether the character is null
If (strstartvalue. tostring () = "")
Change
If (strstartvalue. Length () = 0 ))

3. When comparing strings
Dr ["prefixm"]. tostring (). tolower () = "mm" Use the string. Compare (strprefix, "YY", true) = 0 method.

 
4. Delete parameters not defined in the method.
 
5. Delete invalid values.

5. datareader is not disabled (OtherProgram)

6. The system prompts you to delete unused methods in the program.

7. The system prompts that the specific exception needs to be specified for catch, which saves the memory usage for exception capture.

8. Remove unnecessary using references.

Problems encountered:
1. There are a large number of globalization requirements, but they are not noticed at ordinary times. Although the developed program requires support for multiple languages
Strmonth = startdatevalue. Month. tostring ();

This will prompt the need for multi-language support

2. There is no assembliesshoulddeclareminimumsecurity definition for the program.
Signature is required, but this is usually not noticed.

3. The stored procedure written by CLR requires an out parameter, but it will also be prompted. Therefore, you need to develop a set of detailed rules.

4. If there is a string addition in the loop, it is troublesome to use the stringbuilder modification unless you have noticed it before,

For more information, see
Http://www.cnblogs.com/zhengyun_ustc/archive/2005/08/09/FxCop001.html
Rules
Http://www.cnblogs.com/Hedonister/articles/231878.html
Fxcop tool download connection:
Http://www.gotdotnet.com/team/fxcop/

Example of custom fxcop rules:

Http://www.iocblog.net/static/2007/414.html

fxcop add rules

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.