我们试图在构建时标记外部类型(如 ConfigurationManager
)的使用。
自定义代码分析字典可以提供帮助 [1],但仅限于项目中包含源代码的情况。同样,Obsolete
属性适用于项目中包含的类型。
我什至不确定代码分析规则是否能够检查方法体? [2].
关于我们如何在构建时标记外部类型/方法的使用有什么建议吗?
[1] - http://msdn.microsoft.com/en-us/library/bb514188.aspx
[2] - http://msdn.microsoft.com/en-us/library/dd172127(v=vs.90).aspx
最佳答案
一种方法是创建自定义 FxCop 规则,在代码分析阶段检查字段,如下所示:
internal sealed class SampleRule : BaseIntrospectionRule
{
public override ProblemCollection Check(Member member)
{
const string typeName = "System.DateTime";
var field = member as Field;
if (field == null || field.Type.FullName != typeName)
return null;
return new ProblemCollection
{
new Problem(new Resolution(field.Name.Name, "Type {0} is obsolete", typeName))
};
}
}
我建议您查看 this tutorial .
关于c# - 如何在 .NET 中将外部类型/方法标记为已弃用/过时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12937179/