Rule S1144 advises to remove unused private code. In the following snippet:
using System.Collections.Generic;
using System.IO;
namespace S1144;
public class ResourceCollection
{
private readonly Dictionary<string, Dictionary<string, string?>> resources = [];
public Dictionary<string, string?> this[string key]
{
get
{
if (!resources.TryGetValue(key, out var resoures))
{
resoures = [];
resources[key] = resoures;
}
return resoures;
}
private set => resources[key] = value; // FP, used by line 31.
}
public static ResourceCollection Load(DirectoryInfo dir)
{
var collection = new ResourceCollection();
foreach (var file in dir.GetFiles($"*.resx"))
{
collection[file.Name] = [];
}
return collection;
}
}
It fails to detect the usage of the private setter, that is actually used by line 31: collection[file.Name] = [];, hence the false positive.
Reported by SonarAnalyzer.CSharp v10.34.0.3385