I have a piece of code that is similar to this:
dynamic a = new ValueHolder();
dynamic b = new ValueHolder();
dynamic c = new ValueHolder();
a.MtdActual = b.MtdActual + c.MtdActual;
a.YtdActual = b.YtdActual + c.YtdActual;
a.MtdVariance = b.MtdVariance + c.MtdVariance;
I created this for an example, the cyclomatic complexity of that piece of code according to Code Analysis is 25.
When dissasembling the code in IL spy you can see this:
object a = new ValueHolder();
object b = new ValueHolder();
object c = new ValueHolder();
if (Program.<ConsumeA>o__SiteContainer2.<>p__Site3 == null)
{
Program.<ConsumeA>o__SiteContainer2.<>p__Site3 = CallSite<Func<CallSite, object, object, object>>.Create(Binder.SetMember(CSharpBinderFlags.None, "MtdActual", typeof(Program), new CSharpArgumentInfo[]
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
}));
}
Func<CallSite, object, object, object> arg_159_0 = Program.<ConsumeA>o__SiteContainer2.<>p__Site3.Target;
CallSite arg_159_1 = Program.<ConsumeA>o__SiteContainer2.<>p__Site3;
object arg_159_2 = a;
if (Program.<ConsumeA>o__SiteContainer2.<>p__Site4 == null)
{
Program.<ConsumeA>o__SiteContainer2.<>p__Site4 = CallSite<Func<CallSite, object, object, object>>.Create(Binder.BinaryOperation(CSharpBinderFlags.None, ExpressionType.Add, typeof(Program), new CSharpArgumentInfo[]
{
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
}));
}
...
My question is clearly the if else and compiler generated logic is increasing the complexity. But how can I configure Code Analysis to not operate on this level and rather to evaluate on the simpler coded (pre compilation) stage as the first code snippet, if even possible?