Using the Obsolete Attribute

Problem
You have deprecated types or members, and you don’t want clients using them anymore. What should you do?

Solution
First, start by marking deprecated types and members with the Obsolete attribute. Do this in the first version released with the deprecated types. In subsequent versions, use the true argument of the Obsolete attribute to cause compile-time errors. This should force users to remove any reference to the member.

Comments
Use the Obsolete attribute’s Message property to specify what to use in place of the deprecated code. Also, don’t remove a type or member without marking it obsolete in at least one version of your library.

Example

// This usage causes a compilation warning.
[Obsolete("Use WaitForElement instead")]
void WaitForItem() {
    ...
}

// This usage causes a compilation error.
[Obsolete("Use WaitForElement instead", true)]
void WaitForItem() {
    ...
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s