5

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

Tim
  • 2,887
  • 10
  • 33
  • 33

3 Answers3

8

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
  • 868,454
  • 176
  • 1,908
  • 1,964
0

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
  • 11,631
  • 3
  • 26
  • 34
0

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
  • 51,220
  • 55
  • 213
  • 317