Game Development Reference
In-Depth Information
namespace NexusRules.Naming
{
[CLSCompliant(false)]
abstract public class BaseNexusNamingRule : BaseIntrospectionRule
{
protected BaseNexusNamingRule(string name)
: base(name, “NexusRules.Naming.NamingRules”,
typeof(BaseNexusNamingRule).Assembly)
{
}
}
}
You will notice the arguments being passed into the base constructor. The first
argument is the name of the rule, and it is passed in through the constructor of
each custom rule inheriting from BaseNexusNamingRule . The last two arguments
require more explanation. The second argument is the fully qualified name of the
embedded configuration XML file without the extension. In this example, the
assembly is NexusRules.Naming.dll and the XML configuration file is NamingRules.xml ,
resulting in NexusRules.Naming.NamingRules . The third argument is a reference to
the assembly containing the rules.
It is also important to note the need for [CLSCompliant(false)] ; the FxCop SDK is
not CLS-compliant, so it is required that this attribute be placed so that the code
compiles correctly.
With the base rule class defined, we can create our first FxCop rule. The magic
behind the FxCop SDK is the Check method. There are many different overloaded
versions, all of which get run when an assembly is analyzed; it becomes a matter of
picking the right overloaded method for the job.
Here is the code for the example FxCop rule:
using System;
using Microsoft.Cci;
using Microsoft.Tools.FxCop.Sdk;
using Microsoft.Tools.FxCop.Sdk.Introspection;
namespace NexusRules.Naming
{
[CLSCompliant(false)]
public class NamespacePrefix : BaseNexusNamingRule
{
Search Nedrilad ::




Custom Search