-1

I know there are rules available that fire when a NotImplementedException is left in the code (which I can understand for a release build) (see this answer, or this question), but I would like to have the opposite: have Code Analysis ignore methods that throw a NotImplementedException, as they are known to be unfinished.

Background:
When I develop a block of code, I'd like to test what I have so far, before I'm completely done. I also want CA to be on, so I can correct errors early (like: didn't dispose of resources properly). But as I'm stil developing that code, there are still some stubs that I know will not be used by my test. The body of such a stub usually consists of no more than a throw new NotImplementedException();.

When I build the code, CA complains that the method could be 'static' and that parameters are unused. I know I can suppress the CA-errors, but that means I will have to remember to take those suppressions out when those methods are built and it's an extra build (one to get the messages so I can suppress them and one to really run the code).

My question:
Is there a way to have CA ignore methods that end in a NotImplementedException along (at least) one of the code paths? It would be extra nice if that could be set to only work in debug mode, so you can get warnings about that exception in a release build.

For the record, I'm using VS2010.

Community
  • 1
  • 1
Hans Kesting
  • 38,117
  • 9
  • 79
  • 111

1 Answers1

1

No. There is no such option in Code Analysis.

What you could do is write a custom rule which flags the throwing of a NotImplementedException and then process the Code Analysis outcome and remove any entry with the same target method as the NotImplemented custom rule. This rule should be pretty simple to implement. It would probably suffice to search for any Constructor call on the NotImplementedException class.

But this will only work if you run Code Analysis from the commandline and then post-process the xml file.

You could also mark the method using the GeneratedCodeAttribute, as these will be ignored by default.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
  • Yes, I didn't find any option so I was hoping for some plugin or something. Usage from the command line isn't what I'm after: it should work when I press (Ctrl-)F5. A single attribute that I can remember the syntax of, might be a temporary solution, thanks. – Hans Kesting Jan 05 '12 at 09:24