473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to force a custom compiler warning?

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.

Jun 13 '06 #1
6 11485
"chrisb" <ch**********@gmail.com> wrote:
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

--
http://barrkel.blogspot.com/
Jun 13 '06 #2
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

--
Gabriel Lozano-Morán
The .NET Aficionado
http://www.pointerx.net
"chrisb" <ch**********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
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.

Jun 13 '06 #3
oh my god I complete forgot the warning directive :-D I am working way too
declaritive lately which is messing with my brain..

--
Gabriel Lozano-Morán
The .NET Aficionado
http://www.pointerx.net
"Barry Kelly" <ba***********@gmail.com> wrote in message
news:gl********************************@4ax.com...
"chrisb" <ch**********@gmail.com> wrote:
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

--
http://barrkel.blogspot.com/

Jun 13 '06 #4
Perfect. That's exactly what I was looking for.
Thanks,
Chris.

Barry Kelly wrote:
"chrisb" <ch**********@gmail.com> wrote:
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

--
http://barrkel.blogspot.com/


Jun 13 '06 #5
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

"Barry Kelly" <ba***********@gmail.com> wrote in message
news:gl********************************@4ax.com...
"chrisb" <ch**********@gmail.com> wrote:
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

--
http://barrkel.blogspot.com/

Jun 13 '06 #6
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.

--
Gabriel Lozano-Morán
The .NET Aficionado
http://www.pointerx.net

"Brian Richards" <br*******@gmail.com> wrote in message
news:en**************@TK2MSFTNGP03.phx.gbl...
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

"Barry Kelly" <ba***********@gmail.com> wrote in message
news:gl********************************@4ax.com...
"chrisb" <ch**********@gmail.com> wrote:
> 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

--
http://barrkel.blogspot.com/


Jun 13 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hafeez | last post by:
I am having real trouble compiling this code http://www.cs.wisc.edu/~vganti/birchcode/codeHier/AttrProj.tgz The attachment shows errors when compiled using the current version of g++ in a...
0
by: steven shingler | last post by:
Hi all - would like to write a custom attribute, which, when applied to a constructor will make the compiler issue a warning. Just like the Obsolete Attribute, but with a name of my choosing. Call...
2
by: Glen | last post by:
I'm working on a custom assembly and I'm trying to figure out the best approach to handling known constraints within the assembly, once compiled, to alert the developer at compile time of a...
2
by: MilanB | last post by:
Hi, Is there a way to force Visual C++ compiler (VS 2003) to give an error or notice in case of IF statment have "=" instead of "==" for example if(locationID = 10351) is passing, but I...
5
by: Sorskoot | last post by:
Hi, I'm currently building a DoublePoint class as an extention on the standard Point and PointF classes. The DoublePoint class will be part of a bigger library and may be used by serveral...
2
by: prabhupr | last post by:
Hi Folks I was reading this article (http://www.dotnetbips.com/articles/displayarticle.aspx?id=32) on "Custom Attribute", written by Bipin. The only thing I did not understand in this article...
1
by: TC | last post by:
Every time I open my project, I get a warning which says "There are updated custom wrappers available for the following referenced components: Office." When I double-click on the warning, I get...
1
by: olduncleamos | last post by:
Hi all, Just wondering if it is possible for a custom control to emit compiler warning or even error? It would be great to flag the user at compile time if they made some inconsistent property...
3
by: adaslaw | last post by:
Hi Is it possible to force gcc (or xlc) compiler to emit compilation warning or compilation error for such code: void fooA() throw (MyException) { ... throw MyException(); ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.