Hugo
Hugo

Reputation: 479

How to mark a method that has become obsolete in the next version?

Is there an attribute like Obsolete or Deprecated to indicate that a method has become obsolete or deprecated in the next version of a C# API? Otherwise, is there a standard for indicating that, like adding it in the remarks of a method's documentation?

Upvotes: 1

Views: 2149

Answers (1)

Methran G S
Methran G S

Reputation: 166

You should mark the method as obsolete using the Obsolete annotation. Refer to ObsoleteAttribute for details.

[Obsolete("Your warning message")]
public void MyMethod()
{
    // Method body
}

If you want to throw an error instead of a warning, you could set the second argument error which is a boolean to true.

[Obsolete("Your error message", true)]
public void MyMethod()
{
    // Method body
}

Upvotes: 5

Related Questions