【发布时间】:2014-07-18 13:02:27
【问题描述】:
我正在尝试编写一个 FxCop 规则来匹配带有 Serializable 属性的类,但似乎该属性被忽略了。
例如。给定这个示例类
[Serializable]
[Description]
public class ClassWithSerializableMustHaveSerializableBaseClass : BaseClass
{
}
我原以为我的自定义规则中的这段代码会成功匹配:
public override ProblemCollection Check(TypeNode type)
{
if (type.Attributes.Any(a => a.Type.FullName == typeof(SerializableAttribute).FullName))
{
var problem = new Problem(GetResolution(), type.SourceContext);
Problems.Add(problem);
}
return Problems;
}
但事实并非如此。如果我将匹配类型更改为 DescriptionAttribute,那么它确实有效。 SerializableAttribute 有什么神奇之处,还是我错过了一些明显的东西?
【问题讨论】:
标签: c# .net fxcop fxcop-customrules