chore(sonar): prefer TryGetValue over ContainsKey+indexer (CA1854)

Applied via `dotnet format analyzers --diagnostics CA1854 --severity info`.
Eliminates the duplicate hash lookup in the
`if (d.ContainsKey(k)) d[k]++ else d[k] = 1` pattern. The fixer rewrites
the conditional to `if (d.TryGetValue(k, out var value)) d[k] = ++value;`
which is semantically identical but does the lookup once.

4 files touched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Thom Lamb
2026-05-26 15:46:19 -05:00
co-authored by Claude Opus 4.7
parent f5d539b906
commit 81254c12f9
4 changed files with 9 additions and 13 deletions
@@ -119,9 +119,9 @@ public class StatementParser : SqlServerStatementParser
protected override void PostProcessClauses(SqlClauses clauses, string sql, Dictionary<string, int> clausePositions)
{
// Snowflake-specific: Append LIMIT to ORDER BY if present
if (clausePositions.ContainsKey(KeywordLimit))
if (clausePositions.TryGetValue(KeywordLimit, out int value))
{
var limitClause = sql.Substring(clausePositions[KeywordLimit]).Trim();
var limitClause = sql.Substring(value).Trim();
if (clauses.OrderByClause != null)
{
clauses.OrderByClause.Clause = string.IsNullOrEmpty(clauses.OrderByClause.Clause)