我有一段代碼,它類似於此:動態關鍵字使圈複雜> 25在Visual Studio 2010代碼分析
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;
我建立這個對於一個例子,一塊代碼的圈複雜根據代碼分析是25
當dissasembling在IL代碼窺探你可以看到這一點:
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)
}));
}
...
我的問題是明確的,如果別人和編譯器生成的日誌ic正在增加複雜性。但是,如何將代碼分析配置爲不在此級別上運行,而是將更簡單的編碼(預編譯)階段作爲第一個代碼片段進行評估(如果可能的話)?
這是不可避免的,分析器從IL工作,而不是源代碼。而使用* dynamic *往往會產生對C#活頁夾調用的全部問題。你需要一種不同類型的分析儀。 – 2012-04-24 12:19:41