I am having trouble with FxCop warning CA1006, Microsoft.Design "DoNotNestGenericTypesInMemberSignatures". Specifically, I am designing a ReportCollection<T>
class that inherits from ReadOnlyCollection<Report<T>>
, and its public
constructor takes an IList<Report<T>>
as a parameter.
The suggestion for fixing this warning is not very useful:
"To fix a violation of this rule, change the design to remove the nested type argument." There are two ways I can see so far to change the design as suggested:
- Make the constructor
internal
. This doesn't work in my case. The constructor must bepublic
because this collection class needs to be instantiable by code outside the assembly. - Make the constructor take a
Report<T>[]
instead of anIList<Report<T>>
. This is sub-optimal because external code should have the flexibility of using dynamically-sized data structures likeList<T>
instead of fixed-size arrays.
At this point, I have given up and suppressed this warning. Is there a better solution?
IDictionary<string,IList<string>>
won't be able to accept anIDictionary<string,List<string>>
, but when nested generics are semantically correct I'd favor using them rather than trying to work around them. – Hester