Search code examples
.netcoding-stylefxcopstylecop

How can I find methods without an explicit access modifier?


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.


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.