Posseth.NamedArguments.AnalyzerAndFixer 1.0.1.8

dotnet add package Posseth.NamedArguments.AnalyzerAndFixer --version 1.0.1.8
                    
NuGet\Install-Package Posseth.NamedArguments.AnalyzerAndFixer -Version 1.0.1.8
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Posseth.NamedArguments.AnalyzerAndFixer" Version="1.0.1.8">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Posseth.NamedArguments.AnalyzerAndFixer" Version="1.0.1.8" />
                    
Directory.Packages.props
<PackageReference Include="Posseth.NamedArguments.AnalyzerAndFixer">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Posseth.NamedArguments.AnalyzerAndFixer --version 1.0.1.8
                    
#r "nuget: Posseth.NamedArguments.AnalyzerAndFixer, 1.0.1.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Posseth.NamedArguments.AnalyzerAndFixer@1.0.1.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Posseth.NamedArguments.AnalyzerAndFixer&version=1.0.1.8
                    
Install as a Cake Addin
#tool nuget:?package=Posseth.NamedArguments.AnalyzerAndFixer&version=1.0.1.8
                    
Install as a Cake Tool

Posseth NamedArguments AnalyzerAndFixer

This is a Roslyn analyzer and code fix provider that enforces the use of named arguments in C# method calls and object creations. It helps improve code readability by requiring named arguments for methods with multiple parameters, while allowing exclusions for commonly used methods where positional arguments are preferred.

Features

  • Diagnostic: Warns when positional arguments are used in method calls or object creations with multiple parameters.
  • Code Fix: Automatically adds named arguments to fix the diagnostic.
  • Configurable: Supports configuration via .editorconfig files to customize behavior.
  • Exclusions: Built-in list of excluded methods where positional arguments are acceptable, with options to add custom exclusions.
  • Record Support: Optional mode to only analyze record types.

Update notes

  • v1.1.8 - 2025-06-15 -Analyzer & code-fix test suite fully modernized to .NET 10, xUnit v3, Microsoft Testing Platform and the latest Roslyn testing -framework (1.1.2) using the current DefaultVerifier/TestState pattern � zero warnings, fully compatible with Visual Studio 2026

Installation

NuGet Package

Install the analyzer via NuGet:

dotnet add package Posseth.NamedArguments.AnalyzerAndFixer

Or search for "Posseth.NamedArguments.AnalyzerAndFixer" in the NuGet Package Manager.

Manual Installation

  1. Clone the repository.
  2. Build the project.
  3. Reference the analyzer DLLs in your project or use the VSIX for Visual Studio integration.

Usage

The analyzer will automatically run during compilation and show warnings for method calls that should use named arguments.

Example

Before (triggers diagnostic):

public void Example()
{
    var result = string.Replace("hello world", "world", "universe");
}

After (fixed):

public void Example()
{
    var result = string.Replace(oldValue: "world", newValue: "universe", input: "hello world");
}

Note: string.Replace is excluded by default, so this example won't trigger in practice. Use custom methods or disable exclusions to see the behavior.

Configuration

The analyzer supports several configuration options via .editorconfig files.

Options

  • OnlyForRecords (boolean, default: false): If true, only analyzes method calls on record types.
  • UseDefaultExcludedMethods (boolean, default: true): If true, uses the built-in list of excluded methods.
  • ExcludedMethodNames (string, default: ""): Comma-separated list of additional method names to exclude.

If UseDefaultExcludedMethods is true, the following methods are excluded by default: "char.Equals", "char.CompareTo", "char.GetUnicodeCategory", "char.IsControl", "char.IsDigit", "char.IsLetter", "char.IsLetterOrDigit", "char.IsLower", "char.IsNumber", "char.IsPunctuation", "char.IsSeparator", "char.IsSurrogate", "char.IsSymbol", "char.IsUpper", "char.IsWhiteSpace", "char.ToLower", "char.ToLowerInvariant", "char.ToUpper", "char.ToUpperInvariant", "char.GetNumericValue", "Console.Write", "Console.WriteLine", "Debug.WriteLine", "Trace.WriteLine", "string.Contains", "string.EndsWith", "string.StartsWith", "string.Equals", "string.IndexOf", "string.LastIndexOf", "string.Replace", "string.Split", "string.Trim", "string.TrimStart", "string.TrimEnd", "string.Insert", "string.Remove", "string.Substring", "string.IsNullOrEmpty", "string.IsNullOrWhiteSpace", "string.Join", "string.Concat", "string.Format", "StringBuilder.Append", "StringBuilder.AppendLine", "StringBuilder.Insert", "StringBuilder.Replace", "StringBuilder.Remove", "CharUnicodeInfo.GetUnicodeCategory", "CharUnicodeInfo.GetDigitValue", "CharUnicodeInfo.GetNumericValue", "Math.Min", "Math.Max", "List.Add", "Dictionary.Add", "Enumerable.Where", "Enumerable.Select", "Enumerable.FirstOrDefault", "Enumerable.First", "Enumerable.Any", "Enumerable.OrderBy", "Enumerable.OrderByDescending", "Enumerable.GroupBy", "Enumerable.ToList", "Enumerable.ToArray", "Enumerable.Contains", "Enumerable.ElementAt", "Enumerable.ElementAtOrDefault", "Enumerable.All", "Enumerable.Count", "Enumerable.Last", "Enumerable.LastOrDefault"

Configuration Methods

  1. Create or open an .editorconfig file in the root of your solution or project.
  2. Add the following configuration entries:
# Named Arguments Analyzer Configuration
[*.{cs,vb}]

# Configure OnlyForRecords option
dotnet_diagnostic.PNA1000.OnlyForRecords = true  # or false
dotnet_diagnostic.PNA1000.UseDefaultExcludedMethods = true  # or false

# Configure ExcludedMethodNames option
dotnet_diagnostic.PNA1000.ExcludedMethodNames = ToString,Equals,GetHashCode
Option 2: Configure in Visual Studio
  1. Right-click on your solution in Solution Explorer.
  2. Select Analyze > Configure Code Analysis > For Solution.
  3. In the dialog that appears, find the analyzer (PNA1000).
  4. Configure the settings for OnlyForRecords and ExcludedMethodNames.
Option 3: Configure in Project File (.csproj)

You can also add these settings to your project file:

<PropertyGroup>
  <AnalysisMode>All</AnalysisMode>
</PropertyGroup>
<ItemGroup>
  <EditorConfigFiles Include=".editorconfig" />
</ItemGroup>
<PropertyGroup>
  <AnalyzerConfigFiles Include="$(MSBuildProjectDirectory)\.analyzer.config" />
</PropertyGroup>

Then create a .analyzer.config file with:

is_global = true
PNA1000.OnlyForRecords = true
PNA1000.UseDefaultExcludedMethods = true
PNA1000.ExcludedMethodNames = ToString,Equals,GetHashCode

The most common and recommended approach is Option 1 with the .editorconfig file, as it's the standard way to configure analyzer settings in modern .NET projects.

Contributing

Contributions are welcome! Please open issues or submit pull requests on GitHub.

License

This project is licensed under the MIT License.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1.8 189 11/15/2025
1.0.1.7 167 11/8/2025
1.0.1.6 155 11/8/2025
1.0.1.5 162 11/8/2025
1.0.1.4 162 9/28/2025
1.0.1.3 137 6/7/2025
1.0.1.2 137 6/6/2025
1.0.1.1 164 5/17/2025
1.0.0.1 248 4/15/2025
1.0.0 400 9/3/2024

This version has been upgraded and tested against VS 2026 and net 10