1
- using System . Collections . Generic ;
2
1
using System . IO ;
3
2
using System . Linq ;
4
3
5
4
using Coverlet . Core . Helpers ;
6
- using Coverlet . Core . Extensions ;
7
5
8
6
using Mono . Cecil ;
9
7
using Mono . Cecil . Cil ;
@@ -13,8 +11,8 @@ namespace Coverlet.Core.Instrumentation
13
11
{
14
12
internal class Instrumenter
15
13
{
16
- private string _module ;
17
- private string _identifier ;
14
+ private readonly string _module ;
15
+ private readonly string _identifier ;
18
16
private InstrumenterResult _result ;
19
17
20
18
public Instrumenter ( string module , string identifier )
@@ -48,25 +46,26 @@ public InstrumenterResult Instrument()
48
46
private void InstrumentModule ( )
49
47
{
50
48
using ( var stream = new FileStream ( _module , FileMode . Open , FileAccess . ReadWrite ) )
49
+ using ( var resolver = new DefaultAssemblyResolver ( ) )
51
50
{
52
- var resolver = new DefaultAssemblyResolver ( ) ;
53
51
resolver . AddSearchDirectory ( Path . GetDirectoryName ( _module ) ) ;
54
52
var parameters = new ReaderParameters { ReadSymbols = true , AssemblyResolver = resolver } ;
55
- ModuleDefinition module = ModuleDefinition . ReadModule ( stream , parameters ) ;
56
-
57
- foreach ( var type in module . GetTypes ( ) )
53
+ using ( var module = ModuleDefinition . ReadModule ( stream , parameters ) )
58
54
{
59
- if ( type . CustomAttributes . Any ( a => a . AttributeType . Name == "ExcludeFromCoverageAttribute" || a . AttributeType . Name == "ExcludeFromCoverage" ) )
60
- continue ;
61
-
62
- foreach ( var method in type . Methods )
55
+ foreach ( var type in module . GetTypes ( ) )
63
56
{
64
- if ( ! method . CustomAttributes . Any ( a => a . AttributeType . Name == "ExcludeFromCoverageAttribute" || a . AttributeType . Name == "ExcludeFromCoverage" ) )
65
- InstrumentMethod ( method ) ;
57
+ if ( type . CustomAttributes . Any ( a => a . AttributeType . Name == "ExcludeFromCoverageAttribute" || a . AttributeType . Name == "ExcludeFromCoverage" ) )
58
+ continue ;
59
+
60
+ foreach ( var method in type . Methods )
61
+ {
62
+ if ( ! method . CustomAttributes . Any ( a => a . AttributeType . Name == "ExcludeFromCoverageAttribute" || a . AttributeType . Name == "ExcludeFromCoverage" ) )
63
+ InstrumentMethod ( method ) ;
64
+ }
66
65
}
67
- }
68
66
69
- module . Write ( stream ) ;
67
+ module . Write ( stream ) ;
68
+ }
70
69
}
71
70
}
72
71
@@ -138,7 +137,7 @@ private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor
138
137
return pathInstr ;
139
138
}
140
139
141
- private bool IsBranchTarget ( ILProcessor processor , Instruction instruction )
140
+ private static bool IsBranchTarget ( ILProcessor processor , Instruction instruction )
142
141
{
143
142
foreach ( var _instruction in processor . Body . Instructions )
144
143
{
@@ -155,7 +154,7 @@ private bool IsBranchTarget(ILProcessor processor, Instruction instruction)
155
154
return false ;
156
155
}
157
156
158
- private void ReplaceInstructionTarget ( Instruction instruction , Instruction oldTarget , Instruction newTarget )
157
+ private static void ReplaceInstructionTarget ( Instruction instruction , Instruction oldTarget , Instruction newTarget )
159
158
{
160
159
if ( instruction . Operand is Instruction _instruction )
161
160
{
@@ -175,7 +174,7 @@ private void ReplaceInstructionTarget(Instruction instruction, Instruction oldTa
175
174
}
176
175
}
177
176
178
- private void ReplaceExceptionHandlerBoundary ( ExceptionHandler handler , Instruction oldTarget , Instruction newTarget )
177
+ private static void ReplaceExceptionHandlerBoundary ( ExceptionHandler handler , Instruction oldTarget , Instruction newTarget )
179
178
{
180
179
if ( handler . FilterStart == oldTarget )
181
180
handler . FilterStart = newTarget ;
0 commit comments