Click here to Skip to main content
14,207,205 members
Rate this:
 
Please Sign up or sign in to vote.
I don't think this is possible, but I have always hoped it is.

When you apply [Obsolete("You really shouldn't use this anymore.")] to a member, it causes the compiler to generate a warning or error, which then appears in the Error List in Visual Studio.

It would be amazing to be able to do this when building components for conditions other obsolescence, even something like: [Experimental("This method is still in development and should not be used in production environments.")] and the like.

Anyone?

FYI: System.ObsoleteAttribute is sealed.
Posted
Updated 5-Dec-13 4:21am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Unfortunately there is no magic in the ObsoleteAttribute[^] class. The compiler service looks for this attribute and displays the warnings in the dialog box.

However, you can raise warnings yourself, like:

public void MyMethod()
{
#warning This method is still in development and is not recommended for production.
}


See #warning[^]
   
v3
Comments
Yvan Rodrigues 5-Dec-13 10:21am
   
You know, I think I knew of #warning and #error years ago, and had completely forgotten about them. It doesn't solve my problem, since I (the component creator) will get the warning, not the end-user, but thanks for reminding me about this.
Ron Beyer 5-Dec-13 10:25am
   
It really is too bad there isn't something like a WarningAttribute, but the recognition of the ObsoleteAttribute is purely compiler based and not something built into .NET. There are ways to suppress code analysis messages through attributes, but no way to raise warnings through them.
Ron Beyer 5-Dec-13 10:27am
   
Another alternative is to use the ///summary XML tags to display a message to the user, since this shows up when they use intellisense. Something like:

///<summary>[Experimental] This method does something magical</summary>
public void MyMethod() { }
Yvan Rodrigues 5-Dec-13 10:29am
   
nice tip!
BillWoodruff 5-Dec-13 20:02pm
   
+5 Valuable information that had ... uhh ... slipped me mind: thanks, Ron

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Cookies | Terms of Service
Web04 | 2.8.190612.1 | Last Updated 5 Dec 2013
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100