Why does initializing a list with lambda cause high cyclic complexity?

Initializing a list with lambdas causes IL cyclotromatic complexity: why and how to remove this complexity? For example, the following code causes the static constructor of a class (which is actually generated by the compiler) to be very complex: 1 + list count.

static List<Predicate<string>> list = new List<Predicate<string>>() { s => s == null, s=> s.StartsWith("R"), ... With a lot of predicates like that …. }; 

Note: complexity is calculated using NDepend

+6
c # lambda ndepend cyclomatic-complexity
source share
1 answer

Why? Because ILCC is defined as the number of different branch / branch assignments. This list that you initialize contains a lot of if / then logic contained in lambdas. I believe the language dependent language is lower?

High cyclic complexity is just a hint that your functions are overly complex and therefore difficult to understand and maintain and test. Whether this hint is correct in this case will depend on how you use this list of predicates. But this is exactly so, a hint. Keeping the Central Committee low should not be regarded as a law of nature. If you think that the code is supported and can be verified, pay attention to the high level of ILCC in your documentation, explain why it does not matter, and continue moving.

+2
source share

All Articles