Skip to content

Commit c9debeb

Browse files
Remove need for string allocation in SA1316TupleElementNamesShouldUseCorrectCasing unless a diagnostic will be issued
1 parent 6327501 commit c9debeb

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

StyleCop.Analyzers/StyleCop.Analyzers/NamingRules/SA1316TupleElementNamesShouldUseCorrectCasing.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,18 @@ private static void CheckName(SyntaxNodeAnalysisContext context, StyleCopSetting
115115
var firstCharacterIsLower = char.IsLower(tupleElementName[0]);
116116

117117
bool reportDiagnostic;
118-
string fixedName;
118+
char fixedFirstChar;
119119

120120
switch (settings.NamingRules.TupleElementNameCasing)
121121
{
122122
case TupleElementNameCase.PascalCase:
123123
reportDiagnostic = firstCharacterIsLower;
124-
fixedName = char.ToUpper(tupleElementName[0]) + tupleElementName.Substring(1);
124+
fixedFirstChar = char.ToUpper(tupleElementName[0]);
125125
break;
126126

127127
default:
128128
reportDiagnostic = !firstCharacterIsLower;
129-
fixedName = char.ToLower(tupleElementName[0]) + tupleElementName.Substring(1);
129+
fixedFirstChar = char.ToLower(tupleElementName[0]);
130130
break;
131131
}
132132

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

137137
if (prepareCodeFix)
138138
{
139+
var fixedName = fixedFirstChar + tupleElementName.Substring(1);
139140
diagnosticProperties.Add(ExpectedTupleElementNameKey, fixedName);
140141
}
141142

0 commit comments

Comments
 (0)