3

I am looking for some VS2012 extension or another solution of the following problem:

  1. I want to check that the my C# custom attribute was set to a Public class.
  2. If it is not, then raise an error compiling the project.

I would like to see this test took place in the studio and has been associated with the compilation. And yes, I know it can be done, for example test using Ndepend or make runtime check.

konstantin
  • 33
  • 4

1 Answers1

4

This is not something you can do with the out-of-the-box compiler. You could write an fxcop rule for it, or use a tool like (as you say) NDepend. Or possibly Roslyn when it is released. But this simply isn't something you can do "vanilla".

Frankly, I would say the easiest way to add a check for this would be in your test suite: just use reflection over all types in your key assemblies to check that it is targeted at types that satisfy your custom rules.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • "You could write an fxcop rule for it". Didn't know FxCop supported this. Do you have a handy link? – David Arno Oct 21 '13 at 12:58
  • @DavidArno it has been a while since I tried writing a custom fxcop rule - but it *feels* like simply overriding `BaseIntrospectionRule` / `Check` should suffice - I haven't tried applying it to exactly this scenario, though. It is entirely possible that I'm wrong, too. – Marc Gravell Oct 21 '13 at 13:01
  • *psst, interesting question you might have insight on [over here...](http://stackoverflow.com/questions/19495318)* –  Oct 21 '13 at 13:07