dotnet / roslyn-analyzers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CA2254 should not apply when null coalescing expression is used

drewnoakes opened this issue · comments

Analyzer

Diagnostic ID: CA2254: Template should be a static expression

Analyzer source

SDK: Built-in CA analyzers in .NET 5 SDK or later

Version: SDK 8.0.200

Describe the bug

My understanding is that the diagnostic aims to improve performance by allowing interpolation/concatenation to be avoided when the log message would be filtered out, and the result discarded.

In the case of ?? this seems excessive. While the ?? can be avoided, it's typically a very cheap operation and doesn't allocate (in this example at least);

image