some knowledge

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);
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值