How to mark a class as Deprecated?

C#.NetOopDeprecated

C# Problem Overview


> Possible Duplicate:
> How do I mark a method as Obsolete/Deprecated? - C#

How do you mark a class as deprecated? I do not want to use a class any more in my project, but do not want to delete it before a period of 2 weeks.

C# Solutions


Solution 1 - C#

You need to use the [Obsolete] attribute.

Example:

[Obsolete("Not used any more", true)]
public class MyDeprecatedClass
{
	//...
}

The parameters are optional. The first parameter is for providing the reason it's obsolete, and the last one is to throw an error at compile time instead of a warning.

Solution 2 - C#

As per Doak's answer, but the attribute's second parameter should be set to false if you want the code to compile:

[Obsolete("Not used any more", false)]
public class MyDeprecatedClass
{
        //...
}

This will just throw warnings.

Solution 3 - C#

The reason to not erase a class and deprecate instead is to adhere to some "politeness policies" when your code is an estabished API and then is consumed by third parties.

If you deprecate instead of erase, you give consumers a life cycle policy (e.g., maintenance and existence of the classes until version X.X) in order to allow them to plan a proper migration to your new API.

Solution 4 - C#

If you are using version control I would recommend just deleting the class. There is no reason to have unused code around.

Version control will be a handy undo if you decide later that you want the class.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMister DevView Question on Stackoverflow
Solution 1 - C#Patrick DesjardinsView Answer on Stackoverflow
Solution 2 - C#RebeccaView Answer on Stackoverflow
Solution 3 - C#GabrielView Answer on Stackoverflow
Solution 4 - C#jjnguyView Answer on Stackoverflow