diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs index d18a51ed0..552e49102 100644 --- a/Mono.Cecil/AssemblyReader.cs +++ b/Mono.Cecil/AssemblyReader.cs @@ -166,6 +166,7 @@ protected override void ReadModule () public void ReadModule (ModuleDefinition module, bool resolve_attributes) { + module.ReadingMode = ReadingMode.Immediate; this.resolve_attributes = resolve_attributes; if (module.HasAssemblyReferences) diff --git a/Mono.Cecil/ModuleDefinition.cs b/Mono.Cecil/ModuleDefinition.cs index 22daecb9b..a254ae278 100644 --- a/Mono.Cecil/ModuleDefinition.cs +++ b/Mono.Cecil/ModuleDefinition.cs @@ -921,6 +921,12 @@ public IMetadataTokenProvider LookupToken (MetadataToken token) { return Read (token, (t, reader) => reader.LookupToken (t)); } + + public void ImmediateRead() + { + var moduleReader = new ImmediateModuleReader(Image); + moduleReader.ReadModule (this, resolve_attributes: true); + } readonly object module_lock = new object(); diff --git a/Test/Mono.Cecil.Tests/ModuleTests.cs b/Test/Mono.Cecil.Tests/ModuleTests.cs index 8e73750bf..a78ca4d7e 100644 --- a/Test/Mono.Cecil.Tests/ModuleTests.cs +++ b/Test/Mono.Cecil.Tests/ModuleTests.cs @@ -277,6 +277,17 @@ public void OpenModuleDeferred () } } + + [Test] + public void OpenModuleDeferredAndThenPerformImmediateRead () + { + using (var module = GetResourceModule ("hello.exe", ReadingMode.Deferred)) { + Assert.AreEqual (ReadingMode.Deferred, module.ReadingMode); + module.ImmediateRead(); + Assert.AreEqual (ReadingMode.Immediate, module.ReadingMode); + } + } + [Test] public void OwnedStreamModuleFileName () {