Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top