Rule S2302 helps making use of the nameof() construct, which extremely powerful. It is also a rule that results in some noise now and then:
public static class Embedded
{
public static (string Name, Stream Stream) Resolve(Assembly assembly, string name)
{
var fullName = $"{assembly.GetName().Name}.{name}";
if (assembly.GetManifestResourceStream(fullName) is { } stream1)
{
return (Name: fullName, Stream: stream1);
}
else throw new FileNotFoundException($"Stream '{name}' not found in assembly {assembly}.", name); // Compliant, just a word in a sentence
}
}
Interpolated strings like the on on in this snippet, are tricky, and I guess error prone. Please reconsider the evaluation of interpolated strings. I’m not sure what a good improvement should be, but I do know I see some FP’s on this rule in the codebases I work on.
Note: that this snippet has been simplified compared to the actual code
Reported by SonarAnalyzer.CSharp v10.22.0.136894