문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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)] .

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top