Skip to content

Commit dc58377

Browse files
committed
Instrument class constructors
Fix #142
1 parent d4b4118 commit dc58377

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/coverlet.core/Instrumentation/Instrumenter.cs

Lines changed: 13 additions & 3 deletions
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,17 @@ 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+
MethodDefinition actualMethod = ctor;
98+
if (InstrumentationHelper.IsLocalMethod(ctor.Name))
99+
actualMethod = methods.FirstOrDefault(m => m.Name == ctor.Name.Split('>')[0].Substring(1)) ?? ctor;
100+
101+
if (!actualMethod.CustomAttributes.Any(IsExcludeAttribute))
102+
InstrumentMethod(ctor);
103+
}
94104
}
95105

96106
private void InstrumentMethod(MethodDefinition method)
@@ -167,7 +177,7 @@ private void InstrumentIL(MethodDefinition method)
167177
private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, SequencePoint sequencePoint)
168178
{
169179
if (!_result.Documents.TryGetValue(sequencePoint.Document.Url, out var document))
170-
{
180+
{
171181
document = new Document { Path = sequencePoint.Document.Url };
172182
_result.Documents.Add(document.Path, document);
173183
}
@@ -194,7 +204,7 @@ private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor
194204
private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor processor, Instruction instruction, BranchPoint branchPoint)
195205
{
196206
if (!_result.Documents.TryGetValue(branchPoint.Document, out var document))
197-
{
207+
{
198208
document = new Document { Path = branchPoint.Document };
199209
_result.Documents.Add(document.Path, document);
200210
}

0 commit comments

Comments
 (0)