我有以下课程:
public static class MyClass
{
private static readonly Dictionary<Type, Func<string, object>> valueTypes;
static MyClass()
{
var dictionary = new Dictionary<Type, Func<string, object>>();
dictionary.Add(typeof(bool), x => bool.Parse(x));
dictionary.Add(typeof(byte), x => byte.Parse(x));
dictionary.Add(typeof(char), x => char.Parse(x));
dictionary.Add(typeof(decimal), x => decimal.Parse(x));
dictionary.Add(typeof(double), x => double.Parse(x));
dictionary.Add(typeof(float), x => float.Parse(x));
dictionary.Add(typeof(int), x => int.Parse(x));
dictionary.Add(typeof(long), x => long.Parse(x));
dictionary.Add(typeof(sbyte), x => sbyte.Parse(x));
dictionary.Add(typeof(short), x => short.Parse(x));
dictionary.Add(typeof(uint), x => uint.Parse(x));
dictionary.Add(typeof(ulong), x => ulong.Parse(x));
dictionary.Add(typeof(ushort), x => ushort.Parse(x));
MyClass.valueTypes = dictionary;
}
}
但是,Microsoft 代码分析将此标记为具有 27 的圈复杂度。我不明白为什么一系列带有委托的 Add 调用会导致如此高的圈复杂度。
我能做些什么来降低圈复杂度?