Sonar-dotnet: Rule S4018: Generic methods should provide type parameters

Created on 23 May 2017  路  3Comments  路  Source: SonarSource/sonar-dotnet

RSPEC-4018

The best way to determine the type of generic method is by inference based on the type of arguments that is passed to the method. This is not possible when a parameter type is missing from the argument list.

New Feature

Most helpful comment

Perhaps using the convention of System.Func with naming the generic parameter "TReturn" would be a better alternative?

All 3 comments

Does this rule make sense when the return type is T (instead of void)?

The rule is telling you that the compiler will not be able to infer the types of the method's generic arguments if there are no parameters of that type. If you only use the generic argument to specify return type you will have to always write it, which is fine in many cases. It should be safe to ignore the warning for such methods.

Perhaps using the convention of System.Func with naming the generic parameter "TReturn" would be a better alternative?

Was this page helpful?
0 / 5 - 0 ratings