Obsolete an entire namespace?

2k views Asked by At

Can I mark an entire namespace as obsolete in .NET Framework (3.5 and 4) somehow, or alternativly an entire project?

3

There are 3 answers

1
Andrey On BEST ANSWER

It is not possible. I guess reason is that namespace can span accross different assemblies and even users of the library can use same namespace, so it would obsolete not only your code. Namespace is basically a syntax sugar for name prefix. Namespace can not even be target of an attribute.

0
Espen Burud On

Obsolete attribute can not be applied to namespaces. The ObsoleteAttribute is decorated with [AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event|AttributeTargets.Interface|AttributeTargets.Delegate, Inherited = false)] .

0
Vaccano On

You cannot mark the whole namespace obsolete, but if you own all the code in the namespace you could possibly use inheritance to have both namespaces at the same time:

namespace New.Namespace
{
    /// <summary>
    /// Application contract
    /// </summary>
    public class Application
    {
        /// <summary>
        /// Application Name
        /// </summary>
        public string ApplicationName { get; set; }
        /// <summary>
        /// Application Id
        /// </summary>
        public int ApplicationId { get; set; }
    }
}


namespace old.namespace
{
    /// <summary>
    /// Application contract
    /// </summary>
    [Obsolete]
    public class Application : New.Namespace.Application
    {       

    }
}

You would have to do this too all classes (enums, structs, etc) in your old namespace to provide backwards and forwards compatibility.