我可以以某种方式在 .NET Framework(3.5 和 4)中将整个命名空间标记为过时,或者将整个项目标记为过时吗?
问问题
1538 次
3 回答
13
这不可能。我猜原因是命名空间可以跨越不同的程序集,甚至库的用户也可以使用相同的命名空间,所以它不仅会过时你的代码。命名空间基本上是名称前缀的语法糖。命名空间甚至不能成为属性的目标。
于 2012-01-11T11:57:17.753 回答
1
过时的属性不能应用于命名空间。ObsoleteAttribute 用
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Constructor|AttributeTargets.Method|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Event|AttributeTargets.Interface|AttributeTargets.Delegate, Inherited = false)]
.
于 2012-01-11T12:01:09.980 回答
0
您不能将整个命名空间标记为过时,但如果您拥有命名空间中的所有代码,则可以使用继承同时拥有两个命名空间:
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
{
}
}
您必须对旧命名空间中的所有类(枚举、结构等)都执行此操作,以提供向后和向前兼容性。
于 2020-05-27T17:05:25.593 回答