Quoting from this comment in a new analyzer request.
[...] analyzer here would enforce used of named arguments when you have successive parameters of the same type (or convertible to same type with implicit conversions).
This analyzer looks at an invocation expression (e.g., a method call) and its arguments and suggests using named arguments according to the following rules:
- If a method or ctor has a number of parameters of the same type the invocation's corresponding arguments should be named.
- If named arguments are used for all but one parameter of the same type the analyzer doesn't emit a diagnostic. Two arguments of the same type cannot accidentally take each other's place in the described scenario. So the decision to have all the arguments named is a matter of code-style in this case and we leave it up to the developer.
- If the last parameter is
params
, the analyzer doesn't emit a diagnostic, as we cannot use named arguments in this case.
- Dustin Campbell for CSharpEssentials
- Alireza Habibi for CSharpUseNamedArgumentsCodeRefactoringProvider which provided very useful code examples.
The UseNamedArguments analyzer and code-fix are licensed under the MIT license.
So they can be used freely in commercial applications.