通用类型的 FXCop 违规
FXCop violation for generic types
在方法声明中使用 IList<Dictionary<string, string>>
作为参数类型时发生 FXCop 违规
It doesnt nest generic type IList<Dictionary<string, string>>
我该如何解决这个问题?
原因是:
A nested type argument is a type argument that is also a generic type.
To call a member whose signature contains a nested type argument, the
user must instantiate one generic type and pass this type to the
constructor of a second generic type. The required procedure and
syntax are complex and should be avoided.
它可以帮助您设计更简单的界面。您有 3 个案例:
- 使用
SuppressMessage
属性
- remove the rule from ruleset
- try to fix violations change the design to remove the nested type argument
你可以试试:
public void Method(Dictionary<string, string> param)
并使用:
var list = new IList<Dictionary<string, string>>();
list.Add(new Dictionary<string, string>{{"key1", "value1"}, {"key2", "value2"}});
list.Add(new Dictionary<string, string>{{"key11", "value11"}, {"key22", "value22"}});
foreach(var element in list)
{
Method(element);
}
在方法声明中使用 IList<Dictionary<string, string>>
作为参数类型时发生 FXCop 违规
It doesnt nest generic type
IList<Dictionary<string, string>>
我该如何解决这个问题?
原因是:
A nested type argument is a type argument that is also a generic type. To call a member whose signature contains a nested type argument, the user must instantiate one generic type and pass this type to the constructor of a second generic type. The required procedure and syntax are complex and should be avoided.
它可以帮助您设计更简单的界面。您有 3 个案例:
- 使用
SuppressMessage
属性 - remove the rule from ruleset
- try to fix violations change the design to remove the nested type argument
你可以试试:
public void Method(Dictionary<string, string> param)
并使用:
var list = new IList<Dictionary<string, string>>();
list.Add(new Dictionary<string, string>{{"key1", "value1"}, {"key2", "value2"}});
list.Add(new Dictionary<string, string>{{"key11", "value11"}, {"key22", "value22"}});
foreach(var element in list)
{
Method(element);
}