During analysis, FxCop recursively traverses through the nodes that make up your assemblies. The most interestingnodes are ModuleNode objects, TypeNode objects (such as ClassNode), and Member objects (such asPropertyNode and Method).When FxCop encounters such a node and the TargetVisibility is consistent with any visibility filtering thatyour rule has specified, it calls a Check method. You can override any (or all) of the following methods inheritedfrom BaseIntrospectionRule. By default, these methods perform no operation unless you override them toimplement your rule:
• Check(ModuleNode module) — Checks a .NET module (an assembly consists of one or more modules)
.• Check(Resource resource) — Checks a resource (such as a Bitmap) defined in a module
.• Check(String namespaceName, TypeNodeCollection types) — Checks types in a namespace.
• Check(TypeNode type) — Checks a type (such as ClassNode, Struct, EnumNode, or others).
• Check(Member member) — Checks a member (such as a PropertyNode, Method, Field, or others).
• Check(Parameter parameter) — Checks a parameter for a member.
Introspection Code Model
Node
• AssemblyReference
• AttributeNode
• Expression
• (numerous)
• Instruction
• Member
• EventNode
• Field
• Method
• InstanceInitializer
• StaticInitializer
• PropertyNode
• TypeNode
• ClassNode
• DelegateNode
• EnumNode
• InterfaceNode
• Struct
• (others)
• ModuleNode
• AssemblyNode
• ModuleReference
• SecurityAttribute
• Statement
• (numerous)
Call & Visit
BaseIntrospectionRule has an overridable TargetVisibility property. If you want your rule to check only those elements that are exposed to third parties (for example, public methods in public classes) override this property to return TargetVisibilities.ExternallyVisible. If you do not override this property, FxCop uses TargetVisibilities.All by default.
public override TargetVisibilities TargetVisibility
{
get
{
return TargetVisibilities.NotExternallyVisible;
}
}
In some cases, you may want to
check nodes that are deeper than the Member level such as individual Statement nodes. In this case, you can call a method that starts with
"Visit" to initiate a drilldown. All child nodes will then be recursively visited. You can override Visit methods logically deeper in the node tree to execute code once nodes of those types are visited by the recursion. In such an override, you must call the base class implementation if you want recursion to continue deeper. For example, the following processes all AssignmentStatement nodes in a Method:
public override ProblemCollection Check(Member member)
{
Method methd = member as Method;
if (methd != null)
{
VisitStatements(methd.Body.Statements);
}
return this.Problems;
}
public override void VisitAssignmentStatement(AssignmentStatement assignment)
{
// Process assignment statement. Add to this.Problems if problems are found.
// Uncomment the following if you need to recurse deeper (for example, to the Expression level).
// base.VisitAssignmentStatement(assignment);
}