Code checking and optimization using FxCop

Source: Internet
Author: User
Some time ago made a use of a Microsoft's free test tool FxCop, after using it feels good, can do some automated testing of code, but also help to learn coding specifications and improve the efficiency of code execution, thereby improving the overall quality of the code.

Where this tool can be tested are: design, globalization (globalization), interoperability (interoperability), naming (naming), performance (performance rules), or the ability to add rules for testing;

The tool is still very useful, and soon it's up.
There are a few tips
1 can customize the wrong rules, suggest to cancel the Globalizationrules,securityrules and other rules

2-point connection to a problem and can be connected directly to code that has a code problem

3 can look at breaking's info comment, there is a better way to solve


The code modified after the check has

1 naming rules for class

2 The judgment character is empty
if (strstartvalue.tostring () = = "")
Switch
if (strstartvalue.length () = = 0))


3 When comparing strings
dr["PREFIXM"]. ToString (). ToLower () = = "MM" instead of String.Compare (Strprefix, "yy", true) = = 0 method


4 Remove parameters that are not used as defined in the method

5 Deleting an invalid assignment

5 DataReader not closed (in other programs)

6 tips for removing unused methods in a program

7 hint catch requires specific exception to be specified, which saves memory usage when capturing exception

8 Removing redundant using references

The problems encountered are
1 There are a lot of globalization requirements, but usually not noticed, although the development of the program requires support for multiple languages
Strmonth = StartDateValue.Month.ToString ();

This will prompt you for multi-lingual support.

2 program does not have assembliesshoulddeclareminimumsecurity definition
Signature is required, but this is usually not noticed.

3 The CLR writes a stored procedure that requires an out parameter, but is also prompted, so a more detailed set of rules needs to be developed

4 in the loop where there is a string addition, it is suggested to use StringBuilder this modification is more troublesome, unless can be noted before,
  • Related Article

    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.