SonarSource/sonar-dotnet

Add ImmutableDictionary.Create(key, value) static extension

Opened this issue · 0 comments

Once we have C# 13 available:

Add ImmutableDictionary.Create<TKey, TValue>(TKey key, TValue value) static extension method that will replace all usages of

ImmutableDictionary<string, string>.Empty.Add(someKey, someValue)

In case there are some troubles with generics, it can also be ImmutableDictionary.Create(string key, string value). The goal is to replace

ImmutableDictionary<string, string>.Empty.Add(IsReportingOnLeftKey, isReportingOnLeftKey.ToString())

with

ImmutableDictionary.Create(IsReportingOnLeftKey, isReportingOnLeftKey.ToString())

This piece of code is a recurring pattern used with ReportIssue overloads that are using the properties parameter to communicate with codefixes. See #9353