diff options
author | Jb Evain <jbevain@gmail.com> | 2011-10-27 16:53:07 +0400 |
---|---|---|
committer | Jb Evain <jbevain@gmail.com> | 2011-10-27 16:53:07 +0400 |
commit | 8771de6415d3fa5e34b12fd90519a5405c02e8b2 (patch) | |
tree | 0a1707ab3fc77c49d3f5f6f51628089ccffb1d19 /Test/Mono.Cecil.Tests/Addin.cs | |
parent | ecdd7454b53a4d6b57c9eb2a500b91025a63b401 (diff) |
First pass at a branch with reduced memory usage; Keeps an open handle on the file, dispose your modules
Diffstat (limited to 'Test/Mono.Cecil.Tests/Addin.cs')
-rw-r--r-- | Test/Mono.Cecil.Tests/Addin.cs | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/Test/Mono.Cecil.Tests/Addin.cs b/Test/Mono.Cecil.Tests/Addin.cs index 38b02ce..469d158 100644 --- a/Test/Mono.Cecil.Tests/Addin.cs +++ b/Test/Mono.Cecil.Tests/Addin.cs @@ -153,19 +153,20 @@ namespace Mono.Cecil.Tests { ModuleDefinition RoundTrip (string location, ReaderParameters reader_parameters, string folder) { - var module = ModuleDefinition.ReadModule (location, reader_parameters); - var rt_folder = Path.Combine (Path.GetTempPath (), folder); - if (!Directory.Exists (rt_folder)) - Directory.CreateDirectory (rt_folder); - var rt_module = Path.Combine (rt_folder, Path.GetFileName (location)); - - var writer_parameters = new WriterParameters { - SymbolWriterProvider = GetSymbolWriterProvider (attribute), - }; + var rt_folder = Path.Combine(Path.GetTempPath(), folder); + if (!Directory.Exists(rt_folder)) + Directory.CreateDirectory(rt_folder); + var rt_module = Path.Combine(rt_folder, Path.GetFileName(location)); + + using (var module = ModuleDefinition.ReadModule (location, reader_parameters)) { + var writer_parameters = new WriterParameters { + SymbolWriterProvider = GetSymbolWriterProvider (attribute), + }; - Reflect.InvokeMethod (Method, Fixture, new object [] { module }); + Reflect.InvokeMethod (Method, Fixture, new object [] { module }); - module.Write (rt_module, writer_parameters); + module.Write (rt_module, writer_parameters); + } if (attribute.Verify) CompilationService.Verify (rt_module); @@ -176,11 +177,13 @@ namespace Mono.Cecil.Tests { public override TestResult RunTest () { var result = new TestResult (TestName); - var module = GetModule (); - if (module == null) - return result; - Reflect.InvokeMethod (Method, Fixture, new object [] { module }); + using (var module = GetModule ()) { + if (module == null) + return result; + + Reflect.InvokeMethod (Method, Fixture, new object [] { module }); + } result.Success (); return result; |