これは実際には非常に簡単なルールです。ほとんどの場合、アセンブリごとに1つのモジュールが存在するため、問題は発生しません。ただし、アセンブリごとに複数のモジュールがあるため、アセンブリごとに重複する問題通知が得られた場合は、アセンブリごとに複数の問題が発生しないようにチェックを追加できます。
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;
}
すばらしい、ありがとう:任意のレートで
は、ここでのルールの基本的な実装です! –