UseNamedArgs 0.0.2
dotnet add package UseNamedArgs --version 0.0.2
NuGet\Install-Package UseNamedArgs -Version 0.0.2
<PackageReference Include="UseNamedArgs" Version="0.0.2" />
paket add UseNamedArgs --version 0.0.2
#r "nuget: UseNamedArgs, 0.0.2"
// Install UseNamedArgs as a Cake Addin #addin nuget:?package=UseNamedArgs&version=0.0.2 // Install UseNamedArgs as a Cake Tool #tool nuget:?package=UseNamedArgs&version=0.0.2
Suggest method calls that can benefit from using named arguments
This project contains a Roslyn code analyzer and an accompanying code-fix provider that suggest using named arguments when calling a method having successive parameters of the same type.
How to use it?
Simply install this nuget package. The analyzer is going to look for method invocations that can benefit from named arguments across the project.
public static void IntroduceCharacter(string name, string powerLevel) {}
// Elsewhere in your code:
// if `IntroduceCharacter` method is called with positional arguments,
// the analyzer emits a warning, as the the method has two parameters
// of the same type following one another.
IntroduceCharacter(name: "Goku", powerLevel: "Over 9000!");
Supported method kinds
The analyzer supports suggesting named arguments for the following method kinds
- Regular instance and static methods
- Extension methods
- Regular constructors
- Attribute constructors
- Primary constructors
Download and install
Install the UseNamedArgs nuget package. For example, run the following command in the NuGet Package Manager Console.
Install-Package UseNamedArgs
This will download all the binaries, and add necessary analyzer references to your project.
Configuration
Starting in Visual Studio 2019 version 16.3, you can configure the severity of analyzer rules, or diagnostics, in an EditorConfig file, from the light bulb menu, and the error list.
You can add the following to the [*.cs]
section of your .editorconfig.
[*.cs]
dotnet_diagnostic.UseNamedArgs.severity = suggestion
The possible severity values are:
error
warning
suggestion
silent
none
default
(in case of this analyzer, it's equal towarning
)
Please take a look at the documentation for a detailed description.
Thank you!
- John Koerner for Creating a Code Analyzer using F#
- Dustin Campbell for CSharpEssentials
- Alireza Habibi for CSharpUseNamedArgumentsCodeRefactoringProvider which provided very useful code examples.
Learn more about Target Frameworks and .NET Standard.
-
- FSharp.Core (>= 4.5.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Support additional call kinds, such as primary constructors