3

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?

Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116
Nimmi
  • 680
  • 8
  • 18
  • 1
    See [Are there any good workarounds for FxCop warning CA1006?](http://stackoverflow.com/questions/417634/are-there-any-good-workarounds-for-fxcop-warning-ca1006) – Roman Marusyk Aug 15 '16 at 09:09
  • 1
    Also this [Alternative to nested type of type Expression>](http://stackoverflow.com/questions/3441563/alternative-to-nested-type-of-type-expressionfunct) – Roman Marusyk Aug 15 '16 at 09:30
  • You can create a class containing the list, but I would ignore this rule. – Ankit Vijay Aug 15 '16 at 11:39

1 Answers1

2

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);
}
Roman Marusyk
  • 23,328
  • 24
  • 73
  • 116