이 실제로 꽤 쉽게 규칙입니다. 대부분의 경우 어셈블리 당 하나의 모듈이 있으므로 문제가되지 않습니다. 그러나 어셈블리 당 여러 개의 모듈이 있기 때문에 어셈블리마다 중복 된 문제 알림이 표시되는 경우 어셈블리 당 하나 이상의 문제가 발생하지 않도록 검사를 추가 할 수 있습니다.
private TypeNode AssemblyCompanyAttributeType { get; set; }
public override void BeforeAnalysis()
{
base.BeforeAnalysis();
this.AssemblyCompanyAttributeType = FrameworkAssemblies.Mscorlib.GetType(
Identifier.For("System.Reflection"),
Identifier.For("AssemblyCompanyAttribute"));
}
public override ProblemCollection Check(ModuleNode module)
{
AttributeNode assemblyCompanyAttribute = module.ContainingAssembly.GetAttribute(this.AssemblyCompanyAttributeType);
if (assemblyCompanyAttribute == null)
{
this.Problems.Add(new Problem(this.GetNamedResolution("NoCompanyAttribute"), module));
}
else
{
string companyName = (string)((Literal)assemblyCompanyAttribute.GetPositionalArgument(0)).Value;
if (!string.Equals(companyName, "FooBar Inc.", StringComparison.Ordinal))
{
this.Problems.Add(new Problem(this.GetNamedResolution("WrongCompanyName", companyName), module));
}
}
return this.Problems;
}
멋진, 감사 : 어떤 속도에서
, 여기에 규칙의 기본 구현입니다! –