Skip to content

Commit

Permalink
Remove need for string allocation in SA1316TupleElementNamesShouldUse…
Browse files Browse the repository at this point in the history
…CorrectCasing unless a diagnostic will be issued
  • Loading branch information
bjornhellander committed Mar 22, 2024
1 parent 6327501 commit c9debeb
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,18 @@ private static void CheckName(SyntaxNodeAnalysisContext context, StyleCopSetting
var firstCharacterIsLower = char.IsLower(tupleElementName[0]);

bool reportDiagnostic;
string fixedName;
char fixedFirstChar;

switch (settings.NamingRules.TupleElementNameCasing)
{
case TupleElementNameCase.PascalCase:
reportDiagnostic = firstCharacterIsLower;
fixedName = char.ToUpper(tupleElementName[0]) + tupleElementName.Substring(1);
fixedFirstChar = char.ToUpper(tupleElementName[0]);
break;

default:
reportDiagnostic = !firstCharacterIsLower;
fixedName = char.ToLower(tupleElementName[0]) + tupleElementName.Substring(1);
fixedFirstChar = char.ToLower(tupleElementName[0]);
break;
}

Expand All @@ -136,6 +136,7 @@ private static void CheckName(SyntaxNodeAnalysisContext context, StyleCopSetting

if (prepareCodeFix)
{
var fixedName = fixedFirstChar + tupleElementName.Substring(1);
diagnosticProperties.Add(ExpectedTupleElementNameKey, fixedName);
}

Expand Down

0 comments on commit c9debeb

Please sign in to comment.