diff options
Diffstat (limited to 'test/Mono.Linker.Tests/TestCasesRunner/TestCaseAssemblyResolver.cs')
-rw-r--r-- | test/Mono.Linker.Tests/TestCasesRunner/TestCaseAssemblyResolver.cs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/Mono.Linker.Tests/TestCasesRunner/TestCaseAssemblyResolver.cs b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseAssemblyResolver.cs new file mode 100644 index 000000000..0c3c82583 --- /dev/null +++ b/test/Mono.Linker.Tests/TestCasesRunner/TestCaseAssemblyResolver.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using Mono.Cecil; + +namespace Mono.Linker.Tests.TestCasesRunner { + public class TestCaseAssemblyResolver : DefaultAssemblyResolver { + readonly HashSet<IDisposable> itemsToDispose; + + public TestCaseAssemblyResolver () + { + itemsToDispose = new HashSet<IDisposable> (); + } + + public override AssemblyDefinition Resolve (AssemblyNameReference name, ReaderParameters parameters) + { + var assembly = base.Resolve (name, parameters); + + if (assembly == null) + return null; + + // Don't do any caching because the reader parameters could be different each time + // but we still want to track items that need to be disposed for easy clean up + itemsToDispose.Add (assembly); + + if (assembly.MainModule.SymbolReader != null) + itemsToDispose.Add (assembly.MainModule.SymbolReader); + return assembly; + } + + protected override void Dispose (bool disposing) + { + foreach (var item in itemsToDispose) + item.Dispose (); + + base.Dispose (disposing); + } + } +} |