gpt4 book ai didi

c# - 通用类型的 FXCop 违规

转载 作者:行者123 更新时间:2023-11-30 16:47:50 29 4
gpt4 key购买 nike

在使用 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 个案例:

你可以试试:

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);
}

关于c# - 通用类型的 FXCop 违规,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38952215/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com