Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jbevain@gmail.com>2015-08-27 18:46:25 +0300
committerJb Evain <jbevain@gmail.com>2015-08-27 18:46:25 +0300
commit06add0abde4e61974e146e6d91fd0aad32f41fc6 (patch)
treefaf86ea54ccf387c6b5ca142792a5decac881899
parent12f981e0b482d7dce21c2efa935c9f4d5cbed8b3 (diff)
Do not force the resolution of attributes when writing a deferred Image as we can write them unresolved
-rw-r--r--Mono.Cecil/AssemblyReader.cs44
-rw-r--r--Mono.Cecil/AssemblyWriter.cs6
2 files changed, 30 insertions, 20 deletions
diff --git a/Mono.Cecil/AssemblyReader.cs b/Mono.Cecil/AssemblyReader.cs
index 451ec56..ff53e4c 100644
--- a/Mono.Cecil/AssemblyReader.cs
+++ b/Mono.Cecil/AssemblyReader.cs
@@ -120,6 +120,8 @@ namespace Mono.Cecil {
sealed class ImmediateModuleReader : ModuleReader {
+ private bool resolve;
+
public ImmediateModuleReader (Image image)
: base (image, ReadingMode.Immediate)
{
@@ -129,13 +131,15 @@ namespace Mono.Cecil {
{
this.module.Read (this.module, (module, reader) => {
ReadModuleManifest (reader);
- ReadModule (module);
+ ReadModule (module, resolve: true);
return module;
});
}
- public static void ReadModule (ModuleDefinition module)
+ public void ReadModule (ModuleDefinition module, bool resolve)
{
+ this.resolve = resolve;
+
if (module.HasAssemblyReferences)
Read (module.AssemblyReferences);
if (module.HasResources)
@@ -146,26 +150,24 @@ namespace Mono.Cecil {
ReadTypes (module.Types);
if (module.HasExportedTypes)
Read (module.ExportedTypes);
- if (module.HasCustomAttributes)
- Read (module.CustomAttributes);
+
+ ReadCustomAttributes (module);
var assembly = module.Assembly;
if (assembly == null)
return;
- if (assembly.HasCustomAttributes)
- ReadCustomAttributes (assembly);
- if (assembly.HasSecurityDeclarations)
- Read (assembly.SecurityDeclarations);
+ ReadCustomAttributes (assembly);
+ ReadSecurityDeclarations (assembly);
}
- static void ReadTypes (Collection<TypeDefinition> types)
+ void ReadTypes (Collection<TypeDefinition> types)
{
for (int i = 0; i < types.Count; i++)
ReadType (types [i]);
}
- static void ReadType (TypeDefinition type)
+ void ReadType (TypeDefinition type)
{
ReadGenericParameters (type);
@@ -194,7 +196,7 @@ namespace Mono.Cecil {
ReadCustomAttributes (type);
}
- static void ReadGenericParameters (IGenericParameterProvider provider)
+ void ReadGenericParameters (IGenericParameterProvider provider)
{
if (!provider.HasGenericParameters)
return;
@@ -211,13 +213,16 @@ namespace Mono.Cecil {
}
}
- static void ReadSecurityDeclarations (ISecurityDeclarationProvider provider)
+ void ReadSecurityDeclarations (ISecurityDeclarationProvider provider)
{
if (!provider.HasSecurityDeclarations)
return;
var security_declarations = provider.SecurityDeclarations;
+ if (!resolve)
+ return;
+
for (int i = 0; i < security_declarations.Count; i++) {
var security_declaration = security_declarations [i];
@@ -225,13 +230,16 @@ namespace Mono.Cecil {
}
}
- static void ReadCustomAttributes (ICustomAttributeProvider provider)
+ void ReadCustomAttributes (ICustomAttributeProvider provider)
{
if (!provider.HasCustomAttributes)
return;
var custom_attributes = provider.CustomAttributes;
+ if (!resolve)
+ return;
+
for (int i = 0; i < custom_attributes.Count; i++) {
var custom_attribute = custom_attributes [i];
@@ -239,7 +247,7 @@ namespace Mono.Cecil {
}
}
- static void ReadFields (TypeDefinition type)
+ void ReadFields (TypeDefinition type)
{
var fields = type.Fields;
@@ -262,7 +270,7 @@ namespace Mono.Cecil {
}
}
- static void ReadMethods (TypeDefinition type)
+ void ReadMethods (TypeDefinition type)
{
var methods = type.Methods;
@@ -294,7 +302,7 @@ namespace Mono.Cecil {
}
}
- static void ReadParameters (MethodDefinition method)
+ void ReadParameters (MethodDefinition method)
{
var parameters = method.Parameters;
@@ -311,7 +319,7 @@ namespace Mono.Cecil {
}
}
- static void ReadProperties (TypeDefinition type)
+ void ReadProperties (TypeDefinition type)
{
var properties = type.Properties;
@@ -327,7 +335,7 @@ namespace Mono.Cecil {
}
}
- static void ReadEvents (TypeDefinition type)
+ void ReadEvents (TypeDefinition type)
{
var events = type.Events;
diff --git a/Mono.Cecil/AssemblyWriter.cs b/Mono.Cecil/AssemblyWriter.cs
index b96d42d..2fd8e2c 100644
--- a/Mono.Cecil/AssemblyWriter.cs
+++ b/Mono.Cecil/AssemblyWriter.cs
@@ -66,8 +66,10 @@ namespace Mono.Cecil {
if ((module.Attributes & ModuleAttributes.ILOnly) == 0)
throw new NotSupportedException ("Writing mixed-mode assemblies is not supported");
- if (module.HasImage && module.ReadingMode == ReadingMode.Deferred)
- ImmediateModuleReader.ReadModule (module);
+ if (module.HasImage && module.ReadingMode == ReadingMode.Deferred) {
+ var immediate_reader = new ImmediateModuleReader (module.Image);
+ immediate_reader.ReadModule (module, resolve: false);
+ }
module.MetadataSystem.Clear ();