views:

244

answers:

4

Possible Duplicate:
Custom Compiler Warnings

Duplicate: http://stackoverflow.com/questions/154109/custom-compiler-warnings/154254

I'm new to writing my own Attributes for .NET, but would like to write one that behaves similarly to the System.ObsoleteAttribute attribute--if a class/member is tagged with the attribute I would like any caller of that class/member to generate a warning.

Specifically I'd like to create an [Unimplemented] attribute--and in practice use it during development rather than throwing NotImplementedExceptions.

Does anyone know how to have the IDE evaluate it in real-time and generate a warning if an [Unimplemented] item is called?

+1  A: 

No, ObsoleteAttribute are treated in a very special way by the CLI-compliant compilers, so there's no way to mimic its behavior. #warning or #error (see this) might do the job.

Anton Gogolev
well that's disappointing; I was hoping to make it a department standard and write an FxCop rule to enforce it.
STW
+2  A: 

I believe this is a duplicate of Custom Compiler Warnings.

Malcolm
It would appear to be close enough to count in my book--I'll close this one out.
STW
Does this mean we can mark this question Obsolete ;)
Mark
+1  A: 

Attributes don't actually do anything, they basically just tag the method (or class or whatever) with some metadata. It is the IDE/compiler that does the processing to decide what to do when it sees the Obsolete attribute.

If you wanted visual studio to behave in this way for another attribute, you would have to write a custom plug-in for visual studio.

Simon P Stevens
A: 

Can I ask why you want to do this? It sounds like you've got some unimplemented features but you don't want them throwing NotImplementedExceptions? Why not have an empty code block with maybe a //todo: comment to remind yourself that you're not finished?

As an aside, there's a great feature in ReSharper called the 'Todo explorer' which shows (and links) to all of your //todo: comments (and even NotImplementedExceptions)

Steve Dunn
The NotImplementedException is only useful if you a: hit it during runtime, or b: remember to search for it before check-in. The ObsoleteAttribute provides a more pro-active reminder that there are empty methods. Perhaps I'll take the suggestion from: http://stackoverflow.com/questions/410719/notimplementedexception-are-they-kidding-me/410800#410800 and implement the provided FxCop rule
STW
...and [Obsolete] isn't intended for unimplemented classes/members. We use it as-intended, so filtering the "real obsoletes" from the "unimplemented obsoletes" wouldn't be a good solution
STW