开发者

Attribute to mark code

开发者 https://www.devze.com 2023-01-03 02:48 出处:网络
In c# there are attributes such as [obsolete] that create compiler warnings that will be shown in visual studio.

In c# there are attributes such as [obsolete] that create compiler warnings that will be shown in visual studio.

Is there an attribute that I can use to mark a method or a class with a comment that should be shown as a warning in visual studio when I compile?

Something like:

[TBD(Msg="Please change me after 2010 07 20")]
public void Foo(){
}

or is there a possibility that I can derive from System.Attribute and make my own attribute, configuring visual studio so that it behaves as I described.

UPDATE

Thanks to all for your answers I have accepted the answer from Robaticus because he showed me the solution that I really needed:

#warning Message

shows the desired message that I wanted and it does this without any overhead. Thanks!

However I searched in the wrong direction and therefore asked the wrong question. For those who are reading this post and are interested in an answer to the initial question, I find the link that Mark Rushakoff has posted is very interesting. In this post, Pablo Fernandez has shown a clever way using an attribute on an attribute 开发者_开发问答to accomplish what I have asked for.


Use the second parameter to do this.

//Compiling error
[System.Obsolete("Obsolete use blah instead", true)]


//Compiling warning
[System.Obsolete("Obsolete use blah instead", false)]


Another option is do do a preprocessor directive:

#warning Please change this code after 2010 07 20
0

精彩评论

暂无评论...
验证码 换一张
取 消