I often end up in a situation where I want to discourage other developers from continuing to use a method or class. For example, let\'s say I have two library methods \"A\" and
Adding the Obsolete attribute to your method will give the strikethrough in intellisense.
[ObsoleteAttribute("This property is obsolete. Use NewProperty instead.", false)]
public static string OldProperty
{ get { return "The old property value."; } }
To disable the warnings add this before the attribute:
#pragma warning disable 612, 618
And to reenable:
#pragma warning restore 612, 618
As noted here, putting a ignore in your project file instead of in your code would be a very clean solution.
618
EDIT: Also, check out @JonHanna's answer about using the EditorBrowsable attribute.
As others have noted, there are actually 2 warnings that are thrown with the obsolete attribute.
EDIT:
#pragma warning disable 612, 618
[Obsolete]
#pragma warning restore 612, 618
public class test1
{...
When you try to use test1
you will get:
Note that when you type var test = new test1()
the strikethrough does not occur.
But test1 test = new test1()
will show the strikethrough.