Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code Analysis Error CA 1006

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();
like image 619
Suresh Kumar Avatar asked Jul 28 '14 05:07

Suresh Kumar


1 Answers

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();
like image 183
Marcel N. Avatar answered Nov 18 '22 20:11

Marcel N.