Skip to content

Commit abd4ae0

Browse files
authored
Merge pull request #147 from latop2604/feature/ctor-coverage
Instrument class constructors
2 parents a189fc2 + 0cd2da0 commit abd4ae0

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/coverlet.core/Instrumentation/Instrumenter.cs

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Diagnostics.CodeAnalysis;
43
using System.IO;
54
using System.Linq;
@@ -91,6 +90,13 @@ private void InstrumentType(TypeDefinition type)
9190
if (!actualMethod.CustomAttributes.Any(IsExcludeAttribute))
9291
InstrumentMethod(method);
9392
}
93+
94+
var ctors = type.GetConstructors();
95+
foreach (var ctor in ctors)
96+
{
97+
if (!ctor.CustomAttributes.Any(IsExcludeAttribute))
98+
InstrumentMethod(ctor);
99+
}
94100
}
95101

96102
private void InstrumentMethod(MethodDefinition method)
@@ -167,7 +173,7 @@ private void InstrumentIL(MethodDefinition method)
167173
private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, SequencePoint sequencePoint)
168174
{
169175
if (!_result.Documents.TryGetValue(sequencePoint.Document.Url, out var document))
170-
{
176+
{
171177
document = new Document { Path = sequencePoint.Document.Url };
172178
_result.Documents.Add(document.Path, document);
173179
}
@@ -194,7 +200,7 @@ private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor
194200
private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, BranchPoint branchPoint)
195201
{
196202
if (!_result.Documents.TryGetValue(branchPoint.Document, out var document))
197-
{
203+
{
198204
document = new Document { Path = branchPoint.Document };
199205
_result.Documents.Add(document.Path, document);
200206
}

0 commit comments

Comments
 (0)