English 中文(简体)
fxcop custom rules - Avoid having more than one class per file
原标题:
  • 时间:2009-11-23 15:51:38
  •  标签:
  • c#
  • fxcop

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

最佳回答

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)

问题回答

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)...

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.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签