简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM