Question

I would like to mark a method/class... obsolete but only after a specific date. For example this class will be obsolete in 6 month to let other developers to get time to implements the new architecture.

Is there an existing attribute in C# doing that ? Or should I implement my own ?

All projects treat warnings as errors, so the ObsoleteAttribute do not answer this question.

Was it helpful?

Solution

Instead of baking this information into the code, you would usually publish the roadmap of development with any breaking changes that are going to occur. Deprecated features are not necessarily breaking changes.

Even if you code a mechanism for the IDE to consume this "deferred deprecation", the other developers would also need this VS extension in order to consume it.

Just release a document saying what is going to be deprecated/broken and then deprecate it using the attribute when the time comes.

The "treat warnings as errors" would only impact you at the point of deprecation, but this implies that you are vigilant in migrating off of old code and onto newer code. Of course, if you need to provide backwards compatibility you would either need to stop treating warnings as errors (in order to have code that uses deprecated code for support) or suppress the warnings at the point of deprecation, but this can get a little messy.

There is no built in support for deferred deprecation and I don't know of any third party solutions in the wild - so for now you are on your own.

OTHER TIPS

What if you start your methods with something like this ?

void method()
{
    if(System.Diagnostics.Debugger.IsAttached) // you want your application to work, but warn developers
    {
        string DeprecatedFrom = "20001231"; //example date: 31 dec 2000
        if (string.Format("{0:yyyymmdd}",DateTime.Now).Equals(DeprecatedFrom)) throw new NotSupportedException("Don't use this method.");
    }
}

Crude, but effective: method will start throwing when 31 dec 2000 (in the example) is reached.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top