其他分享
首页 > 其他分享> > CodeGo.net>如何解决CA1502代码分析

CodeGo.net>如何解决CA1502代码分析

作者:互联网

根据代码分析结果,以下是警告消息,

CA1502 Avoid excessive complexity ‘METHOD()’ has a cyclomatic complexity of 27. Rewrite or refactor the method to reduce complexity to 25.
BusinessServices ReportService.cs 310

什么是圈复杂度,如何解决?

解决方法:

Wikipedia开始:

The cyclomatic complexity of a section of source code is the count of the number of linearly independent paths through the source code. For instance, if the source code contained no decision points such as IF statements or FOR loops, the complexity would be 1, since there is only a single path through the code. If the code had a single IF statement containing a single condition, there would be two paths through the code: one path where the IF statement is evaluated as TRUE and one path where the IF statement is evaluated as FALSE.

解决此问题的最简单方法是将方法分为两个或更多个较小的方法. Visual Studio的内置重构工具(例如Refactor-> Extract Method)可用于将选定的代码部分提取到另一种方法中.

标签:visual-studio-2012,code-analysis,cyclomatic-complexity,c
来源: https://codeday.me/bug/20191030/1964189.html