How to force a custom compiler warning?

  • Thread starter Thread starter chrisb
  • Start date Start date
C

chrisb

Hi,
Does anyone know if it's possible to generate a custom compiler warning
in vs2005? Something like the //todo: comments (possibly //warning: ),
but it would show up in the warnings on every build with my custom
message?

It would be useful to remind me to do something later that depends upon
code that has yet to be written.

Thanks

Chris.
 
Unfortunately the C# compiler does not yet support custom compile-time
attributes, maybe there will be a WarningAttribute in future versions of the
C# compiler but for now there are two possible solutions:

1. Use the System.ObsoleteAttribute
2. Create a custom warning attribute and write an add-in that will reflect
throughout your solution/project emitting warning messages
 
chrisb said:
Does anyone know if it's possible to generate a custom compiler warning
in vs2005? Something like the //todo: comments (possibly //warning: ),
but it would show up in the warnings on every build with my custom
message?

Is the C# '#warning' directive what you're looking for?

-- Barry
 
oh my god I complete forgot the warning directive :-D I am working way too
declaritive lately which is messing with my brain..
 
I was just having the same conversation here at work. My question was the
same as the OP but #warning does not solve our problem. You only get the
warning with compiling the original Assembly. We were hoping to do something
similar to the ObsoleteAttribute but really we want a WarningAttribute. For
instance to apply to virtual methods to warning developers to only override
them if they *really* know what they are doing.

-Brian
 
I do remember a discussion that was going on with someone from the C#
compiler team a couple of years ago about the possibility of adding custom
compile-time attributes so that's why this was the first thing that came in
my mind and I really believed that there was going to be a WarningAttribute
but I haven't heard from it since.
 
Back
Top