Skip to content

Commit 4404282

Browse files
authored
Merge pull request #327 from sharwell/use-nameof
Use nameof in a few appropriate places
2 parents c2ba965 + 2bfcf18 commit 4404282

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/coverlet.core/Instrumentation/Instrumenter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ private void AddCustomModuleTrackerToModule(ModuleDefinition module)
170170

171171
_customTrackerTypeDef.Fields.Add(fieldClone);
172172

173-
if (fieldClone.Name == "HitsArray")
173+
if (fieldClone.Name == nameof(ModuleTrackerTemplate.HitsArray))
174174
_customTrackerHitsArray = fieldClone;
175-
else if (fieldClone.Name == "HitsFilePath")
175+
else if (fieldClone.Name == nameof(ModuleTrackerTemplate.HitsFilePath))
176176
_customTrackerHitsFilePath = fieldClone;
177177
}
178178

test/coverlet.core.tests/Symbols/CecilSymbolHelperTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void GetBranchPoints_OneBranch()
2828
{
2929
// arrange
3030
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
31-
var method = type.Methods.First(x => x.FullName.Contains("::HasSingleDecision"));
31+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.HasSingleDecision)}"));
3232

3333
// act
3434
var points = CecilSymbolHelper.GetBranchPoints(method);
@@ -50,7 +50,7 @@ public void GetBranchPoints_Using_Where_GeneratedBranchesIgnored()
5050
{
5151
// arrange
5252
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
53-
var method = type.Methods.First(x => x.FullName.Contains("::HasSimpleUsingStatement"));
53+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.HasSimpleUsingStatement)}"));
5454

5555
// act
5656
var points = CecilSymbolHelper.GetBranchPoints(method);
@@ -63,7 +63,7 @@ public void GetBranchPoints_GeneratedBranches_DueToCachedAnonymousMethodDelegate
6363
{
6464
// arrange
6565
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
66-
var method = type.Methods.First(x => x.FullName.Contains("::HasSimpleTaskWithLambda"));
66+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.HasSimpleTaskWithLambda)}"));
6767

6868
// act
6969
var points = CecilSymbolHelper.GetBranchPoints(method);
@@ -76,7 +76,7 @@ public void GetBranchPoints_TwoBranch()
7676
{
7777
// arrange
7878
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
79-
var method = type.Methods.First(x => x.FullName.Contains("::HasTwoDecisions"));
79+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.HasTwoDecisions)}"));
8080

8181
// act
8282
var points = CecilSymbolHelper.GetBranchPoints(method);
@@ -95,7 +95,7 @@ public void GetBranchPoints_CompleteIf()
9595
{
9696
// arrange
9797
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
98-
var method = type.Methods.First(x => x.FullName.Contains("::HasCompleteIf"));
98+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.HasCompleteIf)}"));
9999

100100
// act
101101
var points = CecilSymbolHelper.GetBranchPoints(method);
@@ -113,7 +113,7 @@ public void GetBranchPoints_Switch()
113113
{
114114
// arrange
115115
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
116-
var method = type.Methods.First(x => x.FullName.Contains("::HasSwitch"));
116+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.HasSwitch)}"));
117117

118118
// act
119119
var points = CecilSymbolHelper.GetBranchPoints(method);
@@ -136,7 +136,7 @@ public void GetBranchPoints_SwitchWithDefault()
136136
{
137137
// arrange
138138
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
139-
var method = type.Methods.First(x => x.FullName.Contains("::HasSwitchWithDefault"));
139+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.HasSwitchWithDefault)}"));
140140

141141
// act
142142
var points = CecilSymbolHelper.GetBranchPoints(method);
@@ -159,7 +159,7 @@ public void GetBranchPoints_SwitchWithBreaks()
159159
{
160160
// arrange
161161
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
162-
var method = type.Methods.First(x => x.FullName.Contains("::HasSwitchWithBreaks"));
162+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.HasSwitchWithBreaks)}"));
163163

164164
// act
165165
var points = CecilSymbolHelper.GetBranchPoints(method);
@@ -182,7 +182,7 @@ public void GetBranchPoints_SwitchWithMultipleCases()
182182
{
183183
// arrange
184184
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
185-
var method = type.Methods.First(x => x.FullName.Contains("::HasSwitchWithMultipleCases"));
185+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.HasSwitchWithMultipleCases)}"));
186186

187187
// act
188188
var points = CecilSymbolHelper.GetBranchPoints(method);
@@ -226,7 +226,7 @@ public void GetBranchPoints_UsingWithException_Issue243_IgnoresBranchInFinallyBl
226226
{
227227
// arrange
228228
var type = _module.Types.First(x => x.FullName == typeof(DeclaredConstructorClass).FullName);
229-
var method = type.Methods.First(x => x.FullName.Contains("::UsingWithException_Issue243"));
229+
var method = type.Methods.First(x => x.FullName.Contains($"::{nameof(DeclaredConstructorClass.UsingWithException_Issue243)}"));
230230

231231
// check that the method is laid out the way we discovered it to be during the defect
232232
// @see https://github.com/OpenCover/opencover/issues/243

0 commit comments

Comments
 (0)