简体   繁体   English

如何在fxcop中识别方法

[英]How to identify a Method in fxcop

I am trying the create a custom fxcop rule which checks for all the methods in target assembly having their names NOT starting with the CAPITAL letter. 我正在尝试创建一个自定义fxcop规则,该规则检查目标程序集中具有其名称不是以CAPITAL字母开头的所有方法。 I am pretty successful in doing this but there is one problem. 我这样做很成功,但是有一个问题。 The rule throws error for "delegate methods" as well, for ex. 例如,该规则也会对“代理方法”引发错误。 btnOk_Click which I don't want, is there any way to identify/filter delegate methods in fxcop using any predefined property/method ? 我不想要的btnOk_Click,是否可以使用任何预定义的属性/方法在fxcop中标识/过滤委托方法?

An idea would be to write custom code rules through the tool NDepend instead (Disclaimer: I am one of the developer of the tool). 一个想法是改为通过工具NDepend编写自定义代码规则(免责声明:我是该工具的开发人员之一)。

NDepend is especially conceived to make easy custom code rules edition through LINQ query. NDepend是专门通过LINQ查询来简化自定义代码规则版本的构想。 The following Code Query LINQ (CQLinq) query covers your need: 以下代码查询LINQ (CQLinq)查询满足您的需求:

// <Name>Method name MUST start with CAPITAL</Name>
warnif count > 0 
from m in Application.Assemblies.WithName("TargetAssemblyName").ChildMethods()
where 
  !m.IsSpecialName &&         // Remove getter and setter
  !m.IsGeneratedByCompiler && // Discard methods generated by compiler
  !m.ParentType.IsDelegate &&
  !m.NameLike("^btn") &&      // Use regex here to discard btnOk_Click like method
  !char.IsUpper(m.SimpleName[0])
select m

Just write this code rule in NDepend query editor in VS, and get an immediate feedback: 只需在VS的NDepend查询编辑器中编写此代码规则,即可获得立即反馈:

NDepend自定义代码规则

NDepend code rule can be executed/validated live in VS , or can be executed at Build Process time and validated in a report . NDepend代码规则可以在VS中实时执行/验证 ,或者可以在“构建过程”时执行并在报告中进行验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在FXCop中添加自定义规则以避免方法中的==运算符 - How to Add Custom Rule to FXCop for avoiding == operator inside the method 如何获取FxCop中callvirt IL指令实际调用的方法 - How to get the method actually called by the callvirt IL instruction within FxCop FxCop:异步方法的禁止消息 - FxCop: Suppression message for async method 如何通过自定义规则检测FxCop中SPECIFIC方法的调用 - 在Check方法中放入什么 - How to detect calls to a SPECIFIC method in FxCop via a custom rule — what to put in Check method 当你的实现是一个空方法时,你如何“正确”实现Dispose()(根据FxCop)? (CA1063) - How do you “properly” implement Dispose() (according to FxCop) when your implementation is an empty method? (CA1063) 如何将fxcop文件导入stylecop - how to Import fxcop file to stylecop C#:使用FxCop SDK的方法的循环复杂度 - C# :Cyclomatic Complexity of a method with FxCop sdk 告诉FxCop另一种方法是调用dispose - Tell FxCop another method is calling dispose 如何识别和调用标记有属性的方法 - How to identify and call a method tagged with an attribute 如何识别方法是否访问默认值 - How to identify whether the method accessing the default value or not
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM