Simplified FxCop Rules SDK [Michael Fanning]

As mentioned previously here and elsewhere, we’re planning to improve and simplify several aspects of FxCop’s extensibility model. This is the first of a series of threads about those improvements, in order to solicit feedback and give custom rules developers a heads up on the coming changes. Here’s the new simplified IIntrospectionRule interface:

 public interface IIntrospectionRule : IManagedCodeRule
  Problem[] Check(string namespaceName, TypeNodeList types);
  Problem[] Check(Module theModule);
  Problem[] Check(Resource resource);
  Problem[] Check(TypeNode type);
  Problem[] Check(Member member);

This rather drastic simplification has reduced surface area for custom rules and increased FxCop performance without limiting the kinds of checks rules developers can right. Do you need an Assembly rule? Implement a Module rule and check the argument to be sure it’s an assembly node. Do you need a Property rule? Implement a member rule and insure the argument is a Property.

Note that parameter checks have been eliminated. Instead, implement a Member rule and use a new helper method, RuleUtilities.GetParameters(members) to determine whether there’s a parameter list to analyze (this helper returns parameters for both properties and methods). Problem class constructors will now accept a parameter argument if you want to associate a message with a specific parameter.

All comments, questions, and feedback are welcome

Comments (1)

  1. Chris says:

    Why yet another API for reading assemblies? Can’t you just use Reflection or the Reflector CodeModel interfaces so people don’t have to learn this over and over again?