Code analysis throws error CA1006: Do not nest generic types in member signatures whenever we define custom definitions in the interface contract. What is the best way of handling this so called design issue. Any deep thoughts on this.
Thanks for your valuable time to go through this.
Example:-
Task<IList<Employee>> LoadAllEmployeeAsync();
CA1006: Do not nest generic types in member signatures
I think the rule is pretty clear. However, the reasoning behind it is that whoever uses your class must undergo a complex process for instantiating the complex parameter(s) and decreases the adoption rate of new libraries.
However, if we think about it, the rule does not make much sense in this context. First of all, you have a nested complex generic return type, which might not be as bad as a similar parameter. Secondly, I don't think the rule was design for async methods.
I suggest to suppress it on the methods that exhibit this return type. Do not abuse it, so make sure to place it only on async methods and only when the return type is complex:
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures", Justification="This is an async method.")]
Task<IList<Employee>> LoadAllEmployeeAsync();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With