Home > Backend Development > C#.Net Tutorial > Use FxCop for code inspection and optimization

Use FxCop for code inspection and optimization

巴扎黑
Release: 2016-12-20 17:22:43
Original
1344 people have browsed it

Some time ago, I made a use of Microsoft's free testing tool FxCop. After using it, I found it to be quite good. It can perform some automatic testing of codes. It also helps to learn coding standards and improve code execution efficiency, thereby improving the overall quality of the code.

The places this tool can test are: Design, Globalization, Interoperability, Naming, Performance (performance rules), you can also add your own rules for testing;

The tool is very easy to use, and I got started quickly
There are a few tips
1. You can customize the wrong rules. It is recommended to cancel globalizationrules, securityrules and other rules

2. Connect the problematic link in point 2, and then you can directly connect to the link with the problem. For code problems

3, you can look at breaking’s Info comments, which have better solutions


The modified code after inspection is

1 Class naming rules

2 Judgment that the character is empty by
if ( strStartValue.ToString() == "")
Changed to
if (strStartValue.Length() == 0))


3 When comparing strings
dr["PrefixM"].ToString().ToLower() == "mm" Use String.Compare(strPrefix, "yy", true) == 0 method


4 Delete unused parameters defined in the method

5 Delete invalid assignments

5 in DataReader Not closed (in other programs)

6 Prompt to delete unused methods in the program

7 Prompt that catch needs to specify a specific Exception, which can save memory usage when catching Exception

8 Delete redundant using references

The problems encountered are
1 There are a lot of Globalization requirements, but I usually don’t notice it. Although the developed program requires support for multiple languages ​​
strMonth = StartDateValue.Month.ToString();

This will prompt that multi-language support is required

2 The program does not have AssembliesShouldDeclareMinimumSecurity defined
It needs to be signed, but this is usually not noticed at ordinary times

3 The stored procedure written by CLR needs to have out parameters, but it will also be prompted, so a more detailed set of rules needs to be formulated

4 Wherever there are string additions in the loop, it is prompted to use stringbuilder. This modification is quite troublesome unless you pay attention to it beforehand,

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template