Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 7 Next »

How to use a custom rule

Just as the xml rules engines, the C# rules engines can be extended with custom rules.
The process is pretty simple. Once you have packaged your custom rule in a dll file and added it to your FxCop/Gendarme installation, you need to add an XML file describing this rule in the "$SONAR_HOME/extensions/rules/ENGINE" where $SONAR_HOME is the root directory of your sonar installation and ENGINE is either "fxcop" or "gendarme".
Below details on the format of these files.

FxCop XML format

RULE_CLASS being the name of the .net rule class.
ASSEMBLY.DLL being the name of the dll assembly file containing the rule class.
The XML fragment above assumes that the dll is located in the same directory as the standard fxcop assembly rules files.

Example

Let's assume you have implemented a rule that checks if variable name follows a naming convention. You have implemented it in a class called "VariableConventionNameCheck", and you have compiled it into a "MyNamingConvetions.dll" assembly file.

Then, you should write the following code snippet in the XML file:

Gendarme XML format

RULE_CLASS being the name of the .net rule class.
ASSEMBLY.DLL being the name of the dll assembly file containing the rule class. This file should be located in the installation directory of Gendarme, among the dll files provided by Gendarme out of the box.

See the example of FxCop XML format, this is the same principle.

StyleCop XML format

Example:

  • No labels