Reputation: 4845
I am trying to write a custom rule in FxCop to validate if my namespace starts with a particular word. I have tried something like below:
public override ProblemCollection Check(string namespaceName, TypeNodeCollection types)
{
if (namespaceName == null)
{
return this.Problems;
}
if (!namespaceName.StartsWith("FujiXerox.ApeosWare.", StringComparison.Ordinal))
{
this.Problems.Add(new Problem(this.GetNamedResolution("NamespaceResolution", namespaceName)));
}
return this.Problems;
}
But it is not working. Can anyone please suggest how to write this custom rule correctly.
Upvotes: 2
Views: 207
Reputation: 13842
I don't know with FxCop, but with NDepend (a .NET tool integrated in VS, that let's write custom code rules as C# LINQ queries) you just have to write:
// <Name>Namespace should start with XYZ</Name>
warnif count > 0
from n in Application.Namespaces
where !n.Name.StartsWith("XYZ")
select n
The rule can be:
Disclaimer: I work at NDepend
Upvotes: 1