Search code examples
c#asp.netfxcop

FXCop violation for generic types


While using IList<Dictionary<string, string>> as parameter type in method declaration FXCop violation occurs

It doesnt nest generic type IList<Dictionary<string, string>>

How can I resolve this?


Solution

  • Reason for that is:

    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.

    It helps you to design a simpler interface. You have 3 cases:

    You can try:

    public void Method(Dictionary<string, string> param)
    

    and use:

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