25
25
26
26
using BridgeVs . Build . Util ;
27
27
using BridgeVs . Shared . Common ;
28
- using BridgeVs . Shared . Logging ;
29
28
using Mono . Cecil ;
30
29
using Mono . Cecil . Pdb ;
31
30
using Mono . Cecil . Rocks ;
32
31
using System ;
33
32
using System . Collections . Generic ;
34
33
using System . IO ;
35
34
using System . Linq ;
36
- using System . Threading ;
37
35
using FS = BridgeVs . Shared . FileSystem . FileSystemFactory ;
38
36
39
37
namespace BridgeVs . Build . TypeMapper
@@ -58,7 +56,9 @@ internal class VisualizerAttributeInjector : IDisposable
58
56
59
57
private readonly WriterParameters _writerParameters ;
60
58
61
- private DefaultAssemblyResolver GetAssemblyResolver ( string assemblyDirectoryPath )
59
+ private readonly Stream _assemblyStream ;
60
+
61
+ private static DefaultAssemblyResolver GetAssemblyResolver ( string assemblyDirectoryPath )
62
62
{
63
63
DefaultAssemblyResolver assemblyResolver = new DefaultAssemblyResolver ( ) ;
64
64
assemblyResolver . AddSearchDirectory ( Path . GetDirectoryName ( assemblyDirectoryPath ) ) ;
@@ -104,15 +104,14 @@ public VisualizerAttributeInjector(string targetVisualizerAssemblyPath, string t
104
104
SymbolReaderProvider = createPdbInfo ? new PdbReaderProvider ( ) : null ,
105
105
InMemory = true ,
106
106
ReadSymbols = createPdbInfo ,
107
- ThrowIfSymbolsAreNotMatching = false
107
+ ThrowIfSymbolsAreNotMatching = false ,
108
108
} ;
109
109
110
110
//using a stream is better for testing
111
- using ( Stream file = FS . FileSystem . File . OpenRead ( targetVisualizerAssemblyPath ) )
112
- {
113
- _debuggerVisualizerAssembly = AssemblyDefinition . ReadAssembly ( file , readerParameters ) ;
114
- }
111
+ _assemblyStream = FS . FileSystem . File . OpenRead ( targetVisualizerAssemblyPath ) ;
115
112
113
+ _debuggerVisualizerAssembly = AssemblyDefinition . ReadAssembly ( _assemblyStream , readerParameters ) ;
114
+
116
115
InitializeDebuggerAssembly ( ) ;
117
116
RemapAssembly ( ) ;
118
117
}
@@ -249,7 +248,7 @@ public void SaveDebuggerVisualizer(string debuggerVisualizerDst, IEnumerable<str
249
248
{
250
249
string fileName = Path . GetFileNameWithoutExtension ( debuggerVisualizerDst ) ;
251
250
252
- using ( Stream file = FS . FileSystem . File . Create ( debuggerVisualizerDst ) )
251
+ using ( Stream file = FS . FileSystem . File . OpenWrite ( debuggerVisualizerDst ) )
253
252
{
254
253
_debuggerVisualizerAssembly . Name . Name = fileName ;
255
254
_debuggerVisualizerAssembly . Write ( file , _writerParameters ) ;
@@ -280,6 +279,8 @@ private static string FromCilToTypeName(string fullName)
280
279
281
280
public void Dispose ( )
282
281
{
282
+ _assemblyStream . Dispose ( ) ;
283
+
283
284
_debuggerVisualizerAssembly ? . Dispose ( ) ;
284
285
}
285
286
}
0 commit comments