0

How can I enable code style warnings like CA1002: Do not expose generic lists (or any other "Code Analysis for Managed Code Warnings")?

Part of the link is:

When to Suppress Warnings

Do not suppress a warning from this rule unless the assembly that raises this warning is not meant to be a reusable library. For example, it would be safe to suppress this warning in a performance tuned application where a performance benefit was gained from the use of generic lists.

This let me think, the compiler should show this warnings by some way.

I tried this code (Which seems to be a reason for CA1002 according to this question):

public FooList : List<Foo>
{
}

It compiled fine without a warning. My warning level per project is already at max level 4:

Warning Level

So how can I enable the warnings?

Community
  • 1
  • 1
Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111

1 Answers1

1

Code Analysis warnings are separate from compiler warnings, and are enabled on the "Code Analysis" tab in project properties.

Code Analysis tab on the project properties page

Detailed instructions from MSDN:

  1. In Solution Explorer, right-click the project, and then click Properties.
  2. In the properties dialog box for the project, click Code Analysis.
  3. Specify the build type in Configuration and the target platform in Platform.
  4. To enable or disable automatic code analysis, select or clear the Enable Code Analysis on Build check box.
BJ Myers
  • 6,617
  • 6
  • 34
  • 50