Skip to content

Commit 72a8eb7

Browse files
sharwelldfyx
authored andcommitted
Use nameof instead of literals where applicable
1 parent 02b5dc4 commit 72a8eb7

4 files changed

Lines changed: 24 additions & 24 deletions

File tree

StyleCop.Analyzers/StyleCop.Analyzers.CodeFixes/DocumentationRules/SA1642SA1643CodeFixProvider.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,29 @@ private static Task<Document> GetTransformedDocumentAsync(Document document, Syn
9999
ImmutableArray<string> standardText;
100100
if (declarationSyntax is ConstructorDeclarationSyntax)
101101
{
102-
var typeKindText = resourceManager.GetString(isStruct ? "TypeTextStruct" : "TypeTextClass", culture);
102+
var typeKindText = resourceManager.GetString(isStruct ? nameof(DocumentationResources.TypeTextStruct) : nameof(DocumentationResources.TypeTextClass), culture);
103103
if (declarationSyntax.Modifiers.Any(SyntaxKind.StaticKeyword))
104104
{
105105
standardText = ImmutableArray.Create(
106-
string.Format(resourceManager.GetString("StaticConstructorStandardTextFirstPart", culture), typeKindText),
107-
string.Format(resourceManager.GetString("StaticConstructorStandardTextSecondPart", culture), typeKindText));
106+
string.Format(resourceManager.GetString(nameof(DocumentationResources.StaticConstructorStandardTextFirstPart), culture), typeKindText),
107+
string.Format(resourceManager.GetString(nameof(DocumentationResources.StaticConstructorStandardTextSecondPart), culture), typeKindText));
108108
}
109109
else
110110
{
111111
// Prefer to insert the "non-private" wording for all constructors, even though both are considered
112112
// acceptable for private constructors by the diagnostic.
113113
// https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/413
114114
standardText = ImmutableArray.Create(
115-
string.Format(resourceManager.GetString("NonPrivateConstructorStandardTextFirstPart", culture), typeKindText),
116-
string.Format(resourceManager.GetString("NonPrivateConstructorStandardTextSecondPart", culture), typeKindText));
115+
string.Format(resourceManager.GetString(nameof(DocumentationResources.NonPrivateConstructorStandardTextFirstPart), culture), typeKindText),
116+
string.Format(resourceManager.GetString(nameof(DocumentationResources.NonPrivateConstructorStandardTextSecondPart), culture), typeKindText));
117117
}
118118
}
119119
else if (declarationSyntax is DestructorDeclarationSyntax)
120120
{
121121
standardText =
122122
ImmutableArray.Create(
123-
resourceManager.GetString("DestructorStandardTextFirstPart", culture),
124-
resourceManager.GetString("DestructorStandardTextSecondPart", culture));
123+
resourceManager.GetString(nameof(DocumentationResources.DestructorStandardTextFirstPart), culture),
124+
resourceManager.GetString(nameof(DocumentationResources.DestructorStandardTextSecondPart), culture));
125125
}
126126
else
127127
{

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/PropertySummaryDocumentationAnalyzer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlN
7272
syntax,
7373
diagnosticLocation,
7474
propertyDeclaration,
75-
resourceManager.GetString("StartingTextGetsWhether", culture),
76-
resourceManager.GetString("StartingTextSetsWhether", culture),
77-
resourceManager.GetString("StartingTextGetsOrSetsWhether", culture));
75+
resourceManager.GetString(nameof(DocumentationResources.StartingTextGetsWhether), culture),
76+
resourceManager.GetString(nameof(DocumentationResources.StartingTextSetsWhether), culture),
77+
resourceManager.GetString(nameof(DocumentationResources.StartingTextGetsOrSetsWhether), culture));
7878
}
7979
else
8080
{
@@ -83,9 +83,9 @@ protected override void HandleXmlElement(SyntaxNodeAnalysisContext context, XmlN
8383
syntax,
8484
diagnosticLocation,
8585
propertyDeclaration,
86-
resourceManager.GetString("StartingTextGets", culture),
87-
resourceManager.GetString("StartingTextSets", culture),
88-
resourceManager.GetString("StartingTextGetsOrSets", culture));
86+
resourceManager.GetString(nameof(DocumentationResources.StartingTextGets), culture),
87+
resourceManager.GetString(nameof(DocumentationResources.StartingTextSets), culture),
88+
resourceManager.GetString(nameof(DocumentationResources.StartingTextGetsOrSets), culture));
8989
}
9090
}
9191

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1642ConstructorSummaryDocumentationMustBeginWithStandardText.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,23 @@ private static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext conte
132132
var resourceManager = DocumentationResources.ResourceManager;
133133

134134
bool isStruct = constructorDeclarationSyntax.Parent?.IsKind(SyntaxKind.StructDeclaration) ?? false;
135-
var typeKindText = resourceManager.GetString(isStruct ? "TypeTextStruct" : "TypeTextClass", culture);
135+
var typeKindText = resourceManager.GetString(isStruct ? nameof(DocumentationResources.TypeTextStruct) : nameof(DocumentationResources.TypeTextClass), culture);
136136

137137
if (constructorDeclarationSyntax.Modifiers.Any(SyntaxKind.StaticKeyword))
138138
{
139139
HandleDeclaration(
140140
context,
141-
string.Format(resourceManager.GetString("StaticConstructorStandardTextFirstPart", culture), typeKindText),
142-
string.Format(resourceManager.GetString("StaticConstructorStandardTextSecondPart", culture), typeKindText),
141+
string.Format(resourceManager.GetString(nameof(DocumentationResources.StaticConstructorStandardTextFirstPart), culture), typeKindText),
142+
string.Format(resourceManager.GetString(nameof(DocumentationResources.StaticConstructorStandardTextSecondPart), culture), typeKindText),
143143
Descriptor);
144144
}
145145
else if (constructorDeclarationSyntax.Modifiers.Any(SyntaxKind.PrivateKeyword))
146146
{
147147
var privateConstructorMatch = HandleDeclaration(
148148
context,
149-
string.Format(resourceManager.GetString("PrivateConstructorStandardTextFirstPart", culture), typeKindText),
149+
string.Format(resourceManager.GetString(nameof(DocumentationResources.PrivateConstructorStandardTextFirstPart), culture), typeKindText),
150150
string.Format(
151-
resourceManager.GetString("PrivateConstructorStandardTextSecondPart", culture),
151+
resourceManager.GetString(nameof(DocumentationResources.PrivateConstructorStandardTextSecondPart), culture),
152152
typeKindText),
153153
null);
154154

@@ -161,10 +161,10 @@ private static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext conte
161161
HandleDeclaration(
162162
context,
163163
string.Format(
164-
resourceManager.GetString("NonPrivateConstructorStandardTextFirstPart", culture),
164+
resourceManager.GetString(nameof(DocumentationResources.NonPrivateConstructorStandardTextFirstPart), culture),
165165
typeKindText),
166166
string.Format(
167-
resourceManager.GetString("NonPrivateConstructorStandardTextSecondPart", culture),
167+
resourceManager.GetString(nameof(DocumentationResources.NonPrivateConstructorStandardTextSecondPart), culture),
168168
typeKindText),
169169
Descriptor);
170170
}
@@ -173,10 +173,10 @@ private static void HandleConstructorDeclaration(SyntaxNodeAnalysisContext conte
173173
HandleDeclaration(
174174
context,
175175
string.Format(
176-
resourceManager.GetString("NonPrivateConstructorStandardTextFirstPart", culture),
176+
resourceManager.GetString(nameof(DocumentationResources.NonPrivateConstructorStandardTextFirstPart), culture),
177177
typeKindText),
178178
string.Format(
179-
resourceManager.GetString("NonPrivateConstructorStandardTextSecondPart", culture),
179+
resourceManager.GetString(nameof(DocumentationResources.NonPrivateConstructorStandardTextSecondPart), culture),
180180
typeKindText),
181181
Descriptor);
182182
}

StyleCop.Analyzers/StyleCop.Analyzers/DocumentationRules/SA1643DestructorSummaryDocumentationMustBeginWithStandardText.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ private static void HandleDestructor(SyntaxNodeAnalysisContext context)
9191

9292
HandleDeclaration(
9393
context,
94-
resourceManager.GetString("DestructorStandardTextFirstPart", culture),
95-
resourceManager.GetString("DestructorStandardTextSecondPart", culture),
94+
resourceManager.GetString(nameof(DocumentationResources.DestructorStandardTextFirstPart), culture),
95+
resourceManager.GetString(nameof(DocumentationResources.DestructorStandardTextSecondPart), culture),
9696
Descriptor);
9797
}
9898
}

0 commit comments

Comments
 (0)