Use suppressmessage to prevent fxcop from conducting code analysis.

Source: Internet
Author: User

Recently, I used. NET Compact framwork 3.5 (C #) as a Windows Mobile (6.5) project.CodeThe quality requirements are strict. I thought there was no major problem in the code. I did not expect to use fxcop for an analysis and I had reported more than 400 improvement suggestions.

Fxcop was used for the first time. In fact, visual studio.net 2008 has integrated the code analysis function. Right-click the project and choose Properties> codeanlysis. For details, see.

After "Enable code analysis on build" is selected, compileProgramThe code will be checked automatically at the same time. For non-compliant code, it will be reported in the form of warning. Of course, the proposed specifications may not always be observed in the actual project, after review, we can right-click and select "suppressmessage" to make it no longer displayed.

The same is true for fxcop. After we mark the relevant suppressmessageattribute in the code that violates the rules, fxcop will no longer report this conflict. For example:

[System. Diagnostics. codeanalysis. suppressmessage ("Microsoft. Design", "ca1004: genericmethodsshouldprovidetypeparameter")]
Public static t createform <t> (bool showaftercreated) where T: baseform, new ()
{
Return createform <t> (showaftercreated, true );
}

However, to make the above tag take effect, you must define "in" Conditional compilation symbols "on the build tab of the Project property.Code_analysis",

Suppressmessage can also be defined in assemblyinfo. CS, for example:

// Below attribute is to suppress fxcop warning "ca2232: Microsoft. Usage: Add stathreadattrito to assembly"
// As device app does not support sta thread.
[Assembly: system. Diagnostics. codeanalysis. suppressmessage ("Microsoft. Usage", "ca2232: markwindowsformsentrypointswithstathread")]

If you want to suppressmessage at the project level, you can write it in "globalsuppressions. cs.

Reference: http://blogs.msdn.com/fxcop/archive/2006/03/23/faq-why-does-fxcop-ignore-my-in-code-suppressmessageattribute-suppressions-david-kean.aspx

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.