views:

115

answers:

2

I am using FxCop and I would like to find all the methods or variables without an access modifier explicitly defined. For example:

class MyClass
{
   int myInt = 0;

   internal MyClass()
   {
   }
}

I would like FxCop to warn me that I didn't specify what access modifier will be applied to the variable "myInt" or the class "MyClass". Has anyone done this before, or can anyone offer guidance on where to start?

Update: Just to let everyone know, the StyleCop rule that looks for this is SA1400.

+2  A: 

FxCop analyses the compiled code, which has access modifiers applied. You need to use a tool like StyleCop to detect coding syntax issues such as not explicitly declaring access modifiers.

Jeff Yates
Thanks, StyleCop worked like a champ.
Jon Tackabury
A: 

Using FxCop I beleive the only way to do this would be to write your own custom rule. This blog post is a good place to start.

You may also want to take a look at StyleCop and NDepend. I'm almost certain NDepend will do this (although you may have to write some custom CQL) and I know StyleCop will do this out of the box.

Scott Dorman
FxCop can't detect coding semantics like this as the access modifier is applied during compilation.
Jeff Yates