tags:

views:

196

answers:

3

Hi all,

as fxcop is an assembly inspector, is it possible to create a custom rule that check if there's more than one class per file ?

If yes, how to do that ?

Thanks for your help

+6  A: 

It is not possible to do that. Since FxCop only inspects binaries, it is impossible to tell which file a class was defined it.

However, look at StyleCop, which comes with such a rule out of the box. (SA1402: FileMayOnlyContainASingleClass)

SLaks
shahkalpesh
Thanks for your answer.So bad for fxcop
Tim
It might be possible with pdb files but StyleCop is more suited for this check.
Guillaume
A: 

As you say yourself: FxCop checks the compiled assemblies. Thus, there simply isn't something like a sourcecode file anymore. So the answer is no.

But MS StyleCop (quite similar to FxCop, but analyzing sourcecode files rather than IL code) might be able to do what you want. I don't know, if such a StyleCop rule already exists - if so, it's definitely not in the set of rules that come with StyleCop "out of the box" (i.e. the MS predefined ones...).

HTH!

EDIT: I've seen at the moment, that there actually IS such a rule (see answer above)...

Thomas Weller
There is such a rule in StyleCop; see my answer.
SLaks
thanks for your answer too
Tim
A: 

My thinking...

  • Given that the debuger can display the code for the method/class.
  • The debugger must be able to get the file the method is in use the pdb file.
  • So you should be able to do the same.

Sorry I don't know how to read info from the pdb file.

Ian Ringrose