diff --git a/ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs b/ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs index 2b4a842b2..c5143907b 100644 --- a/ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs +++ b/ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs @@ -49,7 +49,7 @@ namespace ICSharpCode.Decompiler.Tests.Semantics IMethod MakeMethod(params object[] parameterTypesOrDefaultValues) { - var context = new SimpleTypeResolveContext(compilation.MainAssembly); + var context = new SimpleTypeResolveContext(compilation.MainModule); var m = new FakeMethod(compilation, SymbolKind.Method); m.Name = "Method"; var parameters = new List(); diff --git a/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs b/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs index 2cdd5a530..ddc11afa1 100644 --- a/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs +++ b/ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs @@ -159,7 +159,7 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem [Test] public void AssemblyAttribute() { - var attributes = compilation.MainAssembly.GetAssemblyAttributes().ToList(); + var attributes = compilation.MainModule.GetAssemblyAttributes().ToList(); var typeTest = attributes.Single(a => a.AttributeType.FullName == typeof(TypeTestAttribute).FullName); Assert.AreEqual(3, typeTest.FixedArguments.Length); // first argument is (int)42 @@ -185,7 +185,7 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem [Test] public void TypeForwardedTo_Attribute() { - var attributes = compilation.MainAssembly.GetAssemblyAttributes().ToList(); + var attributes = compilation.MainModule.GetAssemblyAttributes().ToList(); var forwardAttribute = attributes.Single(a => a.AttributeType.FullName == typeof(TypeForwardedToAttribute).FullName); Assert.AreEqual(1, forwardAttribute.FixedArguments.Length); var rt = (IType)forwardAttribute.FixedArguments[0].Value; @@ -1813,7 +1813,7 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem var typeRef = ReflectionHelper.ParseReflectionName("System.Func`2, System.Core"); ITypeDefinition c = typeRef.Resolve(compilationWithSystemCore.TypeResolveContext).GetDefinition(); Assert.IsNotNull(c, "System.Func<,> not found"); - Assert.AreEqual("mscorlib", c.ParentAssembly.AssemblyName); + Assert.AreEqual("mscorlib", c.ParentModule.AssemblyName); } public void DelegateIsClass() diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index 501032eb8..e9b5e99e0 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -374,7 +374,7 @@ namespace ICSharpCode.Decompiler.CSharp /// public SyntaxTree DecompileModuleAndAssemblyAttributes() { - var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainAssembly); + var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainModule); var decompileRun = new DecompileRun(settings) { DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(), CancellationToken = CancellationToken @@ -396,13 +396,13 @@ namespace ICSharpCode.Decompiler.CSharp void DoDecompileModuleAndAssemblyAttributes(DecompileRun decompileRun, ITypeResolveContext decompilationContext, SyntaxTree syntaxTree) { - foreach (var a in typeSystem.Compilation.MainAssembly.GetAssemblyAttributes()) { + foreach (var a in typeSystem.Compilation.MainModule.GetAssemblyAttributes()) { var astBuilder = CreateAstBuilder(decompilationContext); var attrSection = new AttributeSection(astBuilder.ConvertAttribute(a)); attrSection.AttributeTarget = "assembly"; syntaxTree.AddChild(attrSection, SyntaxTree.MemberRole); } - foreach (var a in typeSystem.Compilation.MainAssembly.GetModuleAttributes()) { + foreach (var a in typeSystem.Compilation.MainModule.GetModuleAttributes()) { var astBuilder = CreateAstBuilder(decompilationContext); var attrSection = new AttributeSection(astBuilder.ConvertAttribute(a)); attrSection.AttributeTarget = "module"; @@ -439,7 +439,7 @@ namespace ICSharpCode.Decompiler.CSharp /// public SyntaxTree DecompileWholeModuleAsSingleFile() { - var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainAssembly); + var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainModule); var decompileRun = new DecompileRun(settings) { DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(), CancellationToken = CancellationToken @@ -566,7 +566,7 @@ namespace ICSharpCode.Decompiler.CSharp { if (types == null) throw new ArgumentNullException(nameof(types)); - var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainAssembly); + var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainModule); var decompileRun = new DecompileRun(settings) { DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(), CancellationToken = CancellationToken @@ -606,7 +606,7 @@ namespace ICSharpCode.Decompiler.CSharp var type = typeSystem.Compilation.FindType(fullTypeName.TopLevelTypeName).GetDefinition(); if (type == null) throw new InvalidOperationException($"Could not find type definition {fullTypeName} in type system."); - var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainAssembly); + var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainModule); var decompileRun = new DecompileRun(settings) { DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(), CancellationToken = CancellationToken @@ -697,7 +697,7 @@ namespace ICSharpCode.Decompiler.CSharp throw new NotSupportedException(entity.Kind.ToString()); } } - RunTransforms(syntaxTree, decompileRun, parentTypeDef != null ? new SimpleTypeResolveContext(parentTypeDef) : new SimpleTypeResolveContext(typeSystem.MainAssembly)); + RunTransforms(syntaxTree, decompileRun, parentTypeDef != null ? new SimpleTypeResolveContext(parentTypeDef) : new SimpleTypeResolveContext(typeSystem.MainModule)); return syntaxTree; } @@ -776,7 +776,7 @@ namespace ICSharpCode.Decompiler.CSharp { bool addNewModifier = false; var entity = (IEntity)member.GetSymbol(); - var lookup = new MemberLookup(entity.DeclaringTypeDefinition, entity.ParentAssembly); + var lookup = new MemberLookup(entity.DeclaringTypeDefinition, entity.ParentModule); var baseTypes = entity.DeclaringType.GetNonInterfaceBaseTypes().Where(t => entity.DeclaringType != t); if (entity is ITypeDefinition) { diff --git a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs index af7cc2e11..72a92f9bd 100644 --- a/ICSharpCode.Decompiler/CSharp/CallBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/CallBuilder.cs @@ -611,7 +611,7 @@ namespace ICSharpCode.Decompiler.CSharp out IParameterizedMember foundMember) { foundMember = null; - var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); + var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentModule); var or = new OverloadResolution(resolver.Compilation, arguments.SelectArray(a => a.ResolveResult), argumentNames: argumentNames, @@ -674,7 +674,7 @@ namespace ICSharpCode.Decompiler.CSharp return false; foundMember = result.Member; } else { - var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); + var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentModule); if (method.AccessorOwner.SymbolKind == SymbolKind.Indexer) { var or = new OverloadResolution(resolver.Compilation, arguments.SelectArray(a => a.ResolveResult), @@ -848,7 +848,7 @@ namespace ICSharpCode.Decompiler.CSharp } MemberLookup lookup = null; if (requireTarget) { - lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); + lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentModule); var rr = lookup.Lookup(target.ResolveResult, method.Name, method.TypeArguments, false) ; needsCast = true; result = rr; diff --git a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs index cb583eb97..0fba9c7f3 100644 --- a/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs @@ -86,7 +86,7 @@ namespace ICSharpCode.Decompiler.CSharp this.settings = settings; this.cancellationToken = cancellationToken; this.compilation = decompilationContext.Compilation; - this.resolver = new CSharpResolver(new CSharpTypeResolveContext(compilation.MainAssembly, null, decompilationContext.CurrentTypeDefinition, decompilationContext.CurrentMember)); + this.resolver = new CSharpResolver(new CSharpTypeResolveContext(compilation.MainModule, null, decompilationContext.CurrentTypeDefinition, decompilationContext.CurrentMember)); this.astBuilder = new TypeSystemAstBuilder(resolver); this.astBuilder.AlwaysUseShortTypeNames = true; this.astBuilder.AddResolveResultAnnotations = true; @@ -209,7 +209,7 @@ namespace ICSharpCode.Decompiler.CSharp var result = resolver.ResolveSimpleName(field.Name, EmptyList.Instance, isInvocationTarget: false) as MemberResolveResult; return !(result == null || result.IsError || !result.Member.Equals(field, NormalizeTypeVisitor.TypeErasure)); } else { - var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentAssembly); + var lookup = new MemberLookup(resolver.CurrentTypeDefinition, resolver.CurrentTypeDefinition.ParentModule); var result = lookup.Lookup(target.ResolveResult, field.Name, EmptyList.Instance, false) as MemberResolveResult; return !(result == null || result.IsError || !result.Member.Equals(field, NormalizeTypeVisitor.TypeErasure)); } diff --git a/ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs b/ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs index 2360ecdb9..27a90226c 100644 --- a/ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs +++ b/ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs @@ -22,7 +22,7 @@ namespace ICSharpCode.Decompiler.CSharp { public static void CollectNamespaces(DecompilerTypeSystem typeSystem, HashSet namespaces) { - foreach (var type in typeSystem.MainAssembly.TypeDefinitions) { + foreach (var type in typeSystem.MainModule.TypeDefinitions) { CollectNamespaces(type, typeSystem, namespaces); } CollectAttributeNamespaces(typeSystem, namespaces); @@ -30,8 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp public static void CollectAttributeNamespaces(DecompilerTypeSystem typeSystem, HashSet namespaces) { - HandleAttributes(typeSystem.MainAssembly.GetAssemblyAttributes(), namespaces); - HandleAttributes(typeSystem.MainAssembly.GetModuleAttributes(), namespaces); + HandleAttributes(typeSystem.MainModule.GetAssemblyAttributes(), namespaces); + HandleAttributes(typeSystem.MainModule.GetModuleAttributes(), namespaces); } public static void CollectNamespaces(IEntity entity, DecompilerTypeSystem typeSystem, @@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.CSharp switch (entity) { case ITypeDefinition td: if (mappingInfo == null) - mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentAssembly.PEFile, entity.MetadataToken); + mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentModule.PEFile, entity.MetadataToken); namespaces.Add(td.Namespace); HandleAttributes(td.GetAttributes(), namespaces); @@ -91,7 +91,7 @@ namespace ICSharpCode.Decompiler.CSharp } if (!method.MetadataToken.IsNil && method.HasBody) { if (mappingInfo == null) - mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentAssembly.PEFile, entity.MetadataToken); + mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentModule.PEFile, entity.MetadataToken); var reader = typeSystem.ModuleDefinition.Reader; var parts = mappingInfo.GetMethodParts((MethodDefinitionHandle)method.MetadataToken).ToList(); foreach (var part in parts) { diff --git a/ICSharpCode.Decompiler/CSharp/Resolver/CSharpOperators.cs b/ICSharpCode.Decompiler/CSharp/Resolver/CSharpOperators.cs index 066fe2b51..aa782a92f 100644 --- a/ICSharpCode.Decompiler/CSharp/Resolver/CSharpOperators.cs +++ b/ICSharpCode.Decompiler/CSharp/Resolver/CSharpOperators.cs @@ -175,8 +175,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver get { return false; } } - IAssembly IEntity.ParentAssembly { - get { return compilation.MainAssembly; } + IModule IEntity.ParentModule { + get { return compilation.MainModule; } } TypeParameterSubstitution IMember.Substitution { diff --git a/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs b/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs index 6642448e9..a13a96b3d 100644 --- a/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs +++ b/ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs @@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver throw new ArgumentNullException("compilation"); this.compilation = compilation; this.conversions = CSharpConversions.Get(compilation); - this.context = new CSharpTypeResolveContext(compilation.MainAssembly); + this.context = new CSharpTypeResolveContext(compilation.MainModule); } public CSharpResolver(CSharpTypeResolveContext context) @@ -94,8 +94,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver get { return context; } } - IAssembly ITypeResolveContext.CurrentAssembly { - get { return context.CurrentAssembly; } + IModule ITypeResolveContext.CurrentModule { + get { return context.CurrentModule; } } CSharpResolver WithContext(CSharpTypeResolveContext newContext) @@ -1536,7 +1536,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver bool TopLevelTypeDefinitionIsAccessible(ITypeDefinition typeDef) { if (typeDef.Accessibility == Accessibility.Internal) { - return typeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly); + return typeDef.ParentModule.InternalsVisibleTo(compilation.MainModule); } return true; } @@ -1651,7 +1651,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver ITypeDefinition currentTypeDefinition = this.CurrentTypeDefinition; bool isInEnumMemberInitializer = this.CurrentMember != null && this.CurrentMember.SymbolKind == SymbolKind.Field && currentTypeDefinition != null && currentTypeDefinition.Kind == TypeKind.Enum; - return new MemberLookup(currentTypeDefinition, this.Compilation.MainAssembly, isInEnumMemberInitializer); + return new MemberLookup(currentTypeDefinition, this.Compilation.MainModule, isInEnumMemberInitializer); } /// @@ -1664,7 +1664,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver // for accessibility purposes. // This avoids a stack overflow when referencing a protected class nested inside the base class // of a parent class. (NameLookupTests.InnerClassInheritingFromProtectedBaseInnerClassShouldNotCauseStackOverflow) - return new MemberLookup(this.CurrentTypeDefinition.DeclaringTypeDefinition, this.Compilation.MainAssembly, false); + return new MemberLookup(this.CurrentTypeDefinition.DeclaringTypeDefinition, this.Compilation.MainModule, false); } else { return CreateMemberLookup(); } diff --git a/ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs b/ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs index eb83f04d0..fc751d3ac 100644 --- a/ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs +++ b/ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs @@ -47,13 +47,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver #endregion readonly ITypeDefinition currentTypeDefinition; - readonly IAssembly currentAssembly; + readonly IModule currentModule; readonly bool isInEnumMemberInitializer; - public MemberLookup(ITypeDefinition currentTypeDefinition, IAssembly currentAssembly, bool isInEnumMemberInitializer = false) + public MemberLookup(ITypeDefinition currentTypeDefinition, IModule currentModule, bool isInEnumMemberInitializer = false) { this.currentTypeDefinition = currentTypeDefinition; - this.currentAssembly = currentAssembly; + this.currentModule = currentModule; this.isInEnumMemberInitializer = isInEnumMemberInitializer; } @@ -116,19 +116,19 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver case Accessibility.Protected: return IsProtectedAccessible(allowProtectedAccess, entity); case Accessibility.Internal: - return IsInternalAccessible(entity.ParentAssembly); + return IsInternalAccessible(entity.ParentModule); case Accessibility.ProtectedOrInternal: - return IsInternalAccessible(entity.ParentAssembly) || IsProtectedAccessible(allowProtectedAccess, entity); + return IsInternalAccessible(entity.ParentModule) || IsProtectedAccessible(allowProtectedAccess, entity); case Accessibility.ProtectedAndInternal: - return IsInternalAccessible(entity.ParentAssembly) && IsProtectedAccessible(allowProtectedAccess, entity); + return IsInternalAccessible(entity.ParentModule) && IsProtectedAccessible(allowProtectedAccess, entity); default: throw new Exception("Invalid value for Accessibility"); } } - bool IsInternalAccessible(IAssembly assembly) + bool IsInternalAccessible(IModule module) { - return assembly != null && currentAssembly != null && assembly.InternalsVisibleTo(currentAssembly); + return module != null && currentModule != null && module.InternalsVisibleTo(currentModule); } bool IsProtectedAccessible(bool allowProtectedAccess, IEntity entity) diff --git a/ICSharpCode.Decompiler/CSharp/Resolver/ReducedExtensionMethod.cs b/ICSharpCode.Decompiler/CSharp/Resolver/ReducedExtensionMethod.cs index 7ef4758a5..0e08b1b63 100644 --- a/ICSharpCode.Decompiler/CSharp/Resolver/ReducedExtensionMethod.cs +++ b/ICSharpCode.Decompiler/CSharp/Resolver/ReducedExtensionMethod.cs @@ -231,9 +231,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver } } - public IAssembly ParentAssembly { + public IModule ParentModule { get { - return baseMethod.ParentAssembly; + return baseMethod.ParentModule; } } diff --git a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs index 2017c37fa..ee6dbe737 100644 --- a/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs +++ b/ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs @@ -204,7 +204,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax public AstType ConvertType(FullTypeName fullTypeName) { if (resolver != null) { - foreach (var asm in resolver.Compilation.Assemblies) { + foreach (var asm in resolver.Compilation.Modules) { var def = asm.GetTypeDefinition(fullTypeName); if (def != null) { return ConvertType(def); diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs index c7958fb35..38ab708d6 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs @@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms usingScope = new UsingScope(usingScope, ns); } } - var currentContext = new CSharpTypeResolveContext(context.TypeSystem.MainAssembly, usingScope.Resolve(context.TypeSystem.Compilation), context.DecompiledTypeDefinition); + var currentContext = new CSharpTypeResolveContext(context.TypeSystem.MainModule, usingScope.Resolve(context.TypeSystem.Compilation), context.DecompiledTypeDefinition); this.resolveContextStack.Push(currentContext); this.resolver = new CSharpResolver(currentContext); } @@ -68,7 +68,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms foreach (string ident in namespaceDeclaration.Identifiers) { usingScope = new UsingScope(usingScope, ident); } - var currentContext = new CSharpTypeResolveContext(previousContext.CurrentAssembly, usingScope.Resolve(previousContext.Compilation)); + var currentContext = new CSharpTypeResolveContext(previousContext.CurrentModule, usingScope.Resolve(previousContext.Compilation)); resolveContextStack.Push(currentContext); try { this.resolver = new CSharpResolver(currentContext); diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs index 6f635fdfd..2ebb89fa2 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs @@ -130,7 +130,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms usingScope = new UsingScope(usingScope, ns); } } - var currentContext = new CSharpTypeResolveContext(context.TypeSystem.MainAssembly, usingScope.Resolve(context.TypeSystem.Compilation), context.DecompiledTypeDefinition); + var currentContext = new CSharpTypeResolveContext(context.TypeSystem.MainModule, usingScope.Resolve(context.TypeSystem.Compilation), context.DecompiledTypeDefinition); this.context.Push(currentContext); this.astBuilder = CreateAstBuilder(currentContext); } @@ -150,7 +150,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms foreach (string ident in namespaceDeclaration.Identifiers) { usingScope = new UsingScope(usingScope, ident); } - var currentContext = new CSharpTypeResolveContext(previousContext.CurrentAssembly, usingScope.Resolve(previousContext.Compilation)); + var currentContext = new CSharpTypeResolveContext(previousContext.CurrentModule, usingScope.Resolve(previousContext.Compilation)); context.Push(currentContext); try { astBuilder = CreateAstBuilder(currentContext); @@ -179,7 +179,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms { if (methodDeclaration.GetSymbol() is IMethod method && CSharpDecompiler.IsWindowsFormsInitializeComponentMethod(method)) { var previousContext = context.Peek(); - var currentContext = new CSharpTypeResolveContext(previousContext.CurrentAssembly); + var currentContext = new CSharpTypeResolveContext(previousContext.CurrentModule); context.Push(currentContext); try { astBuilder = CreateAstBuilder(currentContext); diff --git a/ICSharpCode.Decompiler/CSharp/Transforms/TransformContext.cs b/ICSharpCode.Decompiler/CSharp/Transforms/TransformContext.cs index 5736a5797..b11ee990e 100644 --- a/ICSharpCode.Decompiler/CSharp/Transforms/TransformContext.cs +++ b/ICSharpCode.Decompiler/CSharp/Transforms/TransformContext.cs @@ -51,10 +51,10 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms } /// - /// Returns the assembly that is being decompiled. + /// Returns the module that is being decompiled. /// - public IAssembly DecompiledAssembly { - get { return decompilationContext.CurrentAssembly; } + public IModule DecompiledModule { + get { return decompilationContext.CurrentModule; } } /// diff --git a/ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs b/ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs index fd4fe6dfa..34d6eb836 100644 --- a/ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs +++ b/ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs @@ -23,25 +23,25 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem { public sealed class CSharpTypeResolveContext : ITypeResolveContext { - readonly IAssembly assembly; + readonly IModule module; readonly ResolvedUsingScope currentUsingScope; readonly ITypeDefinition currentTypeDefinition; readonly IMember currentMember; readonly string[] methodTypeParameterNames; - public CSharpTypeResolveContext(IAssembly assembly, ResolvedUsingScope usingScope = null, ITypeDefinition typeDefinition = null, IMember member = null) + public CSharpTypeResolveContext(IModule module, ResolvedUsingScope usingScope = null, ITypeDefinition typeDefinition = null, IMember member = null) { - if (assembly == null) - throw new ArgumentNullException("assembly"); - this.assembly = assembly; + if (module == null) + throw new ArgumentNullException(nameof(module)); + this.module = module; this.currentUsingScope = usingScope; this.currentTypeDefinition = typeDefinition; this.currentMember = member; } - private CSharpTypeResolveContext(IAssembly assembly, ResolvedUsingScope usingScope, ITypeDefinition typeDefinition, IMember member, string[] methodTypeParameterNames) + private CSharpTypeResolveContext(IModule module, ResolvedUsingScope usingScope, ITypeDefinition typeDefinition, IMember member, string[] methodTypeParameterNames) { - this.assembly = assembly; + this.module = module; this.currentUsingScope = usingScope; this.currentTypeDefinition = typeDefinition; this.currentMember = member; @@ -53,11 +53,11 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem } public ICompilation Compilation { - get { return assembly.Compilation; } + get { return module.Compilation; } } - public IAssembly CurrentAssembly { - get { return assembly; } + public IModule CurrentModule { + get { return module; } } public ITypeDefinition CurrentTypeDefinition { @@ -70,7 +70,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem public CSharpTypeResolveContext WithCurrentTypeDefinition(ITypeDefinition typeDefinition) { - return new CSharpTypeResolveContext(assembly, currentUsingScope, typeDefinition, currentMember, methodTypeParameterNames); + return new CSharpTypeResolveContext(module, currentUsingScope, typeDefinition, currentMember, methodTypeParameterNames); } ITypeResolveContext ITypeResolveContext.WithCurrentTypeDefinition(ITypeDefinition typeDefinition) @@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem public CSharpTypeResolveContext WithCurrentMember(IMember member) { - return new CSharpTypeResolveContext(assembly, currentUsingScope, currentTypeDefinition, member, methodTypeParameterNames); + return new CSharpTypeResolveContext(module, currentUsingScope, currentTypeDefinition, member, methodTypeParameterNames); } ITypeResolveContext ITypeResolveContext.WithCurrentMember(IMember member) @@ -90,7 +90,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem public CSharpTypeResolveContext WithUsingScope(ResolvedUsingScope usingScope) { - return new CSharpTypeResolveContext(assembly, usingScope, currentTypeDefinition, currentMember, methodTypeParameterNames); + return new CSharpTypeResolveContext(module, usingScope, currentTypeDefinition, currentMember, methodTypeParameterNames); } } } diff --git a/ICSharpCode.Decompiler/CSharp/TypeSystem/ResolvedUsingScope.cs b/ICSharpCode.Decompiler/CSharp/TypeSystem/ResolvedUsingScope.cs index 0d70e8cc6..8ffa45c0f 100644 --- a/ICSharpCode.Decompiler/CSharp/TypeSystem/ResolvedUsingScope.cs +++ b/ICSharpCode.Decompiler/CSharp/TypeSystem/ResolvedUsingScope.cs @@ -184,8 +184,8 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem get { return EmptyList.Instance; } } - IEnumerable INamespace.ContributingAssemblies { - get { return EmptyList.Instance; } + IEnumerable INamespace.ContributingModules { + get { return EmptyList.Instance; } } ICompilation ICompilationProvider.Compilation { diff --git a/ICSharpCode.Decompiler/CSharp/TypeSystem/TypeOrNamespaceReference.cs b/ICSharpCode.Decompiler/CSharp/TypeSystem/TypeOrNamespaceReference.cs index 3574fa7e8..2ed10e5f4 100644 --- a/ICSharpCode.Decompiler/CSharp/TypeSystem/TypeOrNamespaceReference.cs +++ b/ICSharpCode.Decompiler/CSharp/TypeSystem/TypeOrNamespaceReference.cs @@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem // nested compilation and not in this, we wouldn't be able to map it anyways. var ctx = context as CSharpTypeResolveContext; if (ctx == null) { - ctx = new CSharpTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember); + ctx = new CSharpTypeResolveContext(context.CurrentModule ?? context.Compilation.MainModule, null, context.CurrentTypeDefinition, context.CurrentMember); } return ResolveType(new CSharpResolver(ctx)); diff --git a/ICSharpCode.Decompiler/CSharp/TypeSystem/UsingScope.cs b/ICSharpCode.Decompiler/CSharp/TypeSystem/UsingScope.cs index e50bf0431..88b80d4ce 100644 --- a/ICSharpCode.Decompiler/CSharp/TypeSystem/UsingScope.cs +++ b/ICSharpCode.Decompiler/CSharp/TypeSystem/UsingScope.cs @@ -154,7 +154,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem CacheManager cache = compilation.CacheManager; ResolvedUsingScope resolved = cache.GetShared(this) as ResolvedUsingScope; if (resolved == null) { - var csContext = new CSharpTypeResolveContext(compilation.MainAssembly, parent != null ? parent.Resolve(compilation) : null); + var csContext = new CSharpTypeResolveContext(compilation.MainModule, parent != null ? parent.Resolve(compilation) : null); resolved = (ResolvedUsingScope)cache.GetOrAddShared(this, new ResolvedUsingScope(csContext, this)); } return resolved; diff --git a/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs b/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs index 0cf6fdb03..e2981f22a 100644 --- a/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs +++ b/ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs @@ -126,13 +126,13 @@ namespace ICSharpCode.Decompiler.DebugInfo if (scope == null) return default; - Dictionary assemblyReferences = new Dictionary(); + Dictionary assemblyReferences = new Dictionary(); var writer = new BlobBuilder(); foreach (var import in scope.Usings) { - foreach (var asm in import.ContributingAssemblies) { - if (asm == compilation.MainAssembly) { + foreach (var asm in import.ContributingModules) { + if (asm == compilation.MainModule) { writer.WriteByte(1); writer.WriteCompressedInteger(MetadataTokens.GetHeapOffset(metadata.GetOrAddBlobUTF8(import.FullName))); } else { diff --git a/ICSharpCode.Decompiler/Documentation/GetPotentiallyNestedClassTypeReference.cs b/ICSharpCode.Decompiler/Documentation/GetPotentiallyNestedClassTypeReference.cs index 8b4a9885e..4394157f0 100644 --- a/ICSharpCode.Decompiler/Documentation/GetPotentiallyNestedClassTypeReference.cs +++ b/ICSharpCode.Decompiler/Documentation/GetPotentiallyNestedClassTypeReference.cs @@ -44,7 +44,7 @@ namespace ICSharpCode.Decompiler.Documentation public IType Resolve(ITypeResolveContext context) { string[] parts = typeName.Split('.'); - var assemblies = new [] { context.CurrentAssembly }.Concat(context.Compilation.Assemblies); + var assemblies = new [] { context.CurrentModule }.Concat(context.Compilation.Modules); for (int i = parts.Length - 1; i >= 0; i--) { string ns = string.Join(".", parts, 0, i); string name = parts[i]; diff --git a/ICSharpCode.Decompiler/Documentation/IdStringProvider.cs b/ICSharpCode.Decompiler/Documentation/IdStringProvider.cs index 04921dd93..b32ebdc69 100644 --- a/ICSharpCode.Decompiler/Documentation/IdStringProvider.cs +++ b/ICSharpCode.Decompiler/Documentation/IdStringProvider.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem.Implementation; @@ -61,10 +62,10 @@ namespace ICSharpCode.Decompiler.Documentation AppendTypeName(b, member.DeclaringType, false); b.Append('.'); } - /*if (member.IsExplicitInterfaceImplementation && member.Name.IndexOf('.') < 0 && member.ImplementedInterfaceMembers.Count == 1) { - AppendTypeName(b, member.ImplementedInterfaceMembers[0].DeclaringType, true); + if (member.IsExplicitInterfaceImplementation && member.Name.IndexOf('.') < 0 && member.ExplicitlyImplementedInterfaceMembers.Count() == 1) { + AppendTypeName(b, member.ExplicitlyImplementedInterfaceMembers.First().DeclaringType, true); b.Append('#'); - }*/ + } b.Append(member.Name.Replace('.', '#')); IMethod method = member as IMethod; if (method != null && method.TypeParameters.Count > 0) { @@ -186,7 +187,7 @@ namespace ICSharpCode.Decompiler.Documentation /// A member reference that represents the ID string. /// The syntax of the ID string is invalid /// - /// The member reference will look in first, + /// The member reference will look in first, /// and if the member is not found there, /// it will look in all other assemblies of the compilation. /// @@ -228,7 +229,7 @@ namespace ICSharpCode.Decompiler.Documentation /// The syntax of the ID string is invalid /// /// - /// The type reference will look in first, + /// The type reference will look in first, /// and if the type is not found there, /// it will look in all other assemblies of the compilation. /// diff --git a/ICSharpCode.Decompiler/Documentation/XmlDocKeyProvider.cs b/ICSharpCode.Decompiler/Documentation/XmlDocKeyProvider.cs index e98469560..64a8fa77b 100644 --- a/ICSharpCode.Decompiler/Documentation/XmlDocKeyProvider.cs +++ b/ICSharpCode.Decompiler/Documentation/XmlDocKeyProvider.cs @@ -186,7 +186,7 @@ namespace ICSharpCode.Decompiler.Documentation /// A member reference that represents the ID string. /// The syntax of the ID string is invalid /// - /// The member reference will look in first, + /// The member reference will look in first, /// and if the member is not found there, /// it will look in all other assemblies of the compilation. /// @@ -228,7 +228,7 @@ namespace ICSharpCode.Decompiler.Documentation /// The syntax of the ID string is invalid /// /// - /// The type reference will look in first, + /// The type reference will look in first, /// and if the type is not found there, /// it will look in all other assemblies of the compilation. /// diff --git a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj index e60af3e58..20331d7df 100644 --- a/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj +++ b/ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj @@ -360,9 +360,9 @@ - + - + diff --git a/ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs b/ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs index b89301502..94a416901 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs @@ -260,7 +260,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms { return CSharp.Transforms.IntroduceExtensionMethods.CanTransformToExtensionMethodCall( call.Method, new CSharp.TypeSystem.CSharpTypeResolveContext( - context.TypeSystem.Compilation.MainAssembly, context.UsingScope + context.TypeSystem.Compilation.MainModule, context.UsingScope ) ); } diff --git a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs index fdb0e98bc..871f415fc 100644 --- a/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs +++ b/ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs @@ -178,7 +178,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms possibleIndexVariables.Add(stloc.Variable, (stloc.ChildIndex, stloc.Value)); return true; } - var resolveContext = new CSharpTypeResolveContext(context.TypeSystem.Compilation.MainAssembly, context.UsingScope); + var resolveContext = new CSharpTypeResolveContext(context.TypeSystem.Compilation.MainModule, context.UsingScope); (var kind, var newPath, var values, var targetVariable) = AccessPathElement.GetAccessPath(instructions[pos], rootType, context.Settings, resolveContext, possibleIndexVariables); if (kind == AccessPathKind.Invalid || target != targetVariable) return false; diff --git a/ICSharpCode.Decompiler/Metadata/MetadataExtensions.cs b/ICSharpCode.Decompiler/Metadata/MetadataExtensions.cs index 9ceb8672e..771826e35 100644 --- a/ICSharpCode.Decompiler/Metadata/MetadataExtensions.cs +++ b/ICSharpCode.Decompiler/Metadata/MetadataExtensions.cs @@ -89,12 +89,12 @@ namespace ICSharpCode.Decompiler.Metadata return Disassembler.DisassemblerHelpers.Escape(name); } - public static TypeSystem.IAssemblyReference GetDeclaringAssembly(this TypeReferenceHandle handle, MetadataReader reader) + public static IModuleReference GetDeclaringModule(this TypeReferenceHandle handle, MetadataReader reader) { var tr = reader.GetTypeReference(handle); switch (tr.ResolutionScope.Kind) { case HandleKind.TypeReference: - return ((TypeReferenceHandle)tr.ResolutionScope).GetDeclaringAssembly(reader); + return ((TypeReferenceHandle)tr.ResolutionScope).GetDeclaringModule(reader); case HandleKind.AssemblyReference: var asmRef = reader.GetAssemblyReference((AssemblyReferenceHandle)tr.ResolutionScope); return new DefaultAssemblyReference(reader.GetString(asmRef.Name)); diff --git a/ICSharpCode.Decompiler/Metadata/PEFile.cs b/ICSharpCode.Decompiler/Metadata/PEFile.cs index 03a428eb6..9a3517048 100644 --- a/ICSharpCode.Decompiler/Metadata/PEFile.cs +++ b/ICSharpCode.Decompiler/Metadata/PEFile.cs @@ -28,7 +28,20 @@ using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.Metadata { - public class PEFile : IDisposable, TypeSystem.IAssemblyReference + /// + /// PEFile is the main class the decompiler uses to represent a metadata assembly/module. + /// Every file on disk can be loaded into a standalone PEFile instance. + /// + /// A PEFile can be combined with its referenced assemblies/modules to form a type system, + /// in that case the class is used instead. + /// + /// + /// In addition to wrapping a System.Reflection.Metadata.PEReader, this class + /// contains a few decompiled-specific caches to allow efficiently constructing a type + /// system from multiple PEFiles. This allows the caches to be shared across multiple + /// decompiled type systems. + /// + public class PEFile : IDisposable, TypeSystem.IModuleReference { public string FileName { get; } public PEReader Reader { get; } @@ -157,17 +170,17 @@ namespace ICSharpCode.Decompiler.Metadata } } - public TypeSystem.IAssemblyReference WithOptions(TypeSystemOptions options) + public TypeSystem.IModuleReference WithOptions(TypeSystemOptions options) { return new PEFileWithOptions(this, options); } - IAssembly TypeSystem.IAssemblyReference.Resolve(ITypeResolveContext context) + IModule TypeSystem.IModuleReference.Resolve(ITypeResolveContext context) { - return new MetadataAssembly(context.Compilation, this, TypeSystemOptions.Default); + return new MetadataModule(context.Compilation, this, TypeSystemOptions.Default); } - private class PEFileWithOptions : TypeSystem.IAssemblyReference + private class PEFileWithOptions : TypeSystem.IModuleReference { readonly PEFile peFile; readonly TypeSystemOptions options; @@ -178,9 +191,9 @@ namespace ICSharpCode.Decompiler.Metadata this.options = options; } - IAssembly TypeSystem.IAssemblyReference.Resolve(ITypeResolveContext context) + IModule TypeSystem.IModuleReference.Resolve(ITypeResolveContext context) { - return new MetadataAssembly(context.Compilation, peFile, options); + return new MetadataModule(context.Compilation, peFile, options); } } } diff --git a/ICSharpCode.Decompiler/SRMExtensions.cs b/ICSharpCode.Decompiler/SRMExtensions.cs index c621bfb99..ab3f57318 100644 --- a/ICSharpCode.Decompiler/SRMExtensions.cs +++ b/ICSharpCode.Decompiler/SRMExtensions.cs @@ -403,7 +403,7 @@ namespace ICSharpCode.Decompiler var typeDef = typeSystem.ResolveAsType(handle).GetDefinition(); if (typeDef == null || typeDef.MetadataToken.IsNil) return 0; - reader = typeDef.ParentAssembly.PEFile.Metadata; + reader = typeDef.ParentModule.PEFile.Metadata; var td = reader.GetTypeDefinition((TypeDefinitionHandle)typeDef.MetadataToken); return td.GetLayout().Size; } @@ -413,7 +413,7 @@ namespace ICSharpCode.Decompiler var typeDef = typeSystem.ResolveAsType(handle).GetDefinition(); if (typeDef == null || typeDef.MetadataToken.IsNil) return 0; - reader = typeDef.ParentAssembly.PEFile.Metadata; + reader = typeDef.ParentModule.PEFile.Metadata; var td = reader.GetTypeDefinition((TypeDefinitionHandle)typeDef.MetadataToken); return td.GetLayout().Size; } diff --git a/ICSharpCode.Decompiler/TypeSystem/ApplyAttributeTypeVisitor.cs b/ICSharpCode.Decompiler/TypeSystem/ApplyAttributeTypeVisitor.cs index a4366ce4c..4d8ddf9b1 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ApplyAttributeTypeVisitor.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ApplyAttributeTypeVisitor.cs @@ -126,7 +126,7 @@ namespace ICSharpCode.Decompiler.TypeSystem { if (useTupleTypes && TupleType.IsTupleCompatible(type, out int tupleCardinality)) { if (tupleCardinality > 1) { - var valueTupleAssembly = type.GetDefinition()?.ParentAssembly; + var valueTupleAssembly = type.GetDefinition()?.ParentModule; ImmutableArray elementNames = default; if (tupleElementNames != null && tupleTypeIndex < tupleElementNames.Length) { string[] extractedValues = new string[tupleCardinality]; diff --git a/ICSharpCode.Decompiler/TypeSystem/AssemblyQualifiedTypeName.cs b/ICSharpCode.Decompiler/TypeSystem/AssemblyQualifiedTypeName.cs index 9447788ee..50d23c8df 100644 --- a/ICSharpCode.Decompiler/TypeSystem/AssemblyQualifiedTypeName.cs +++ b/ICSharpCode.Decompiler/TypeSystem/AssemblyQualifiedTypeName.cs @@ -33,7 +33,7 @@ namespace ICSharpCode.Decompiler.TypeSystem public AssemblyQualifiedTypeName(ITypeDefinition typeDefinition) { - this.AssemblyName = typeDefinition.ParentAssembly.AssemblyName; + this.AssemblyName = typeDefinition.ParentModule.AssemblyName; this.TypeName = typeDefinition.FullTypeName; } diff --git a/ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs b/ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs index 4b80f6b9a..f455f8a7b 100644 --- a/ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs +++ b/ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs @@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.TypeSystem readonly ICompilation compilation; readonly IAssemblyResolver assemblyResolver; readonly TypeSystemOptions typeSystemOptions; - readonly MetadataAssembly mainAssembly; + readonly MetadataModule mainModule; public DecompilerTypeSystem(Metadata.PEFile moduleDefinition, IAssemblyResolver assemblyResolver) : this(moduleDefinition, assemblyResolver, new DecompilerSettings()) @@ -103,7 +103,7 @@ namespace ICSharpCode.Decompiler.TypeSystem var mainAssembly = moduleDefinition.WithOptions(typeSystemOptions); // Load referenced assemblies and type-forwarder references. // This is necessary to make .NET Core/PCL binaries work better. - var referencedAssemblies = new List(); + var referencedAssemblies = new List(); var assemblyReferenceQueue = new Queue<(bool IsAssembly, PEFile MainModule, object Reference)>(); var mainMetadata = moduleDefinition.Metadata; foreach (var h in mainMetadata.GetModuleReferences()) { @@ -158,15 +158,15 @@ namespace ICSharpCode.Decompiler.TypeSystem referencedAssemblies.Add(MinimalCorlib.Instance); compilation = new SimpleCompilation(mainAssembly, referencedAssemblies); } - this.mainAssembly = (MetadataAssembly)compilation.MainAssembly; + this.mainModule = (MetadataModule)compilation.MainModule; } public ICompilation Compilation { get { return compilation; } } - public MetadataAssembly MainAssembly { - get { return mainAssembly; } + public MetadataModule MainModule { + get { return mainModule; } } public Metadata.PEFile ModuleDefinition { @@ -174,14 +174,6 @@ namespace ICSharpCode.Decompiler.TypeSystem } public SRM.MetadataReader GetMetadata() => moduleDefinition.Metadata; - - public Metadata.PEFile GetModuleDefinition(IAssembly assembly) - { - if (assembly is MetadataAssembly asm) { - return asm.PEFile; - } - return null; - } public IMember ResolveAsMember(SRM.EntityHandle memberReference) { @@ -212,27 +204,27 @@ namespace ICSharpCode.Decompiler.TypeSystem public IType ResolveAsType(SRM.EntityHandle typeReference) { - return mainAssembly.ResolveType(typeReference, new GenericContext()); + return mainModule.ResolveType(typeReference, new GenericContext()); } public IMethod ResolveAsMethod(SRM.EntityHandle methodReference) { - return mainAssembly.ResolveMethod(methodReference); + return mainModule.ResolveMethod(methodReference); } public IField ResolveAsField(SRM.EntityHandle fieldReference) { - return mainAssembly.ResolveEntity(fieldReference, new GenericContext()) as IField; + return mainModule.ResolveEntity(fieldReference, new GenericContext()) as IField; } public IProperty ResolveAsProperty(SRM.EntityHandle propertyReference) { - return mainAssembly.ResolveEntity(propertyReference, new GenericContext()) as IProperty; + return mainModule.ResolveEntity(propertyReference, new GenericContext()) as IProperty; } public IEvent ResolveAsEvent(SRM.EntityHandle eventReference) { - return mainAssembly.ResolveEntity(eventReference, new GenericContext()) as IEvent; + return mainModule.ResolveEntity(eventReference, new GenericContext()) as IEvent; } public SRM.MethodSignature DecodeMethodSignature(SRM.StandaloneSignatureHandle handle) @@ -241,7 +233,7 @@ namespace ICSharpCode.Decompiler.TypeSystem if (standaloneSignature.GetKind() != SRM.StandaloneSignatureKind.Method) throw new InvalidOperationException("Expected Method signature"); var sig = standaloneSignature.DecodeMethodSignature( - mainAssembly.TypeProvider, + mainModule.TypeProvider, new GenericContext() ); return new SRM.MethodSignature( @@ -261,7 +253,7 @@ namespace ICSharpCode.Decompiler.TypeSystem if (standaloneSignature.GetKind() != SRM.StandaloneSignatureKind.LocalVariables) throw new InvalidOperationException("Expected Local signature"); var types = standaloneSignature.DecodeLocalSignature( - mainAssembly.TypeProvider, + mainModule.TypeProvider, new GenericContext() ); return ImmutableArray.CreateRange(types, ApplyAttributesToType); diff --git a/ICSharpCode.Decompiler/TypeSystem/IAssembly.cs b/ICSharpCode.Decompiler/TypeSystem/IAssembly.cs index 216d919ca..397d657bf 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IAssembly.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IAssembly.cs @@ -17,23 +17,35 @@ // DEALINGS IN THE SOFTWARE. using System.Collections.Generic; -using System.Reflection.Metadata; using ICSharpCode.Decompiler.Metadata; namespace ICSharpCode.Decompiler.TypeSystem { - public interface IAssemblyReference + /// + /// Interface used to help with construction of the type system. + /// + /// + /// The type system is an immutable cyclic data structure: + /// the compilation (ICompilation) has references to all modules, + /// and each module has a reference back to the compilation. + /// + /// Module references are used to solve this cyclic dependency: + /// The compilation constructor accepts module references, + /// and only the IModuleReference.Resolve() function can observe a + /// partially-constructed compilation; but not any user code. + /// + public interface IModuleReference { /// - /// Resolves this assembly. + /// Resolves this metadata module. /// - IAssembly Resolve(ITypeResolveContext context); + IModule Resolve(ITypeResolveContext context); } /// - /// Represents an assembly. + /// Represents a metadata module. /// - public interface IAssembly : ICompilationProvider + public interface IModule : ICompilationProvider { /// /// Gets the underlying metadata file. May return null, if the IAssembly was not created from a PE file. @@ -43,7 +55,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// Gets whether this assembly is the main assembly of the compilation. /// - bool IsMainAssembly { get; } + bool IsMainModule { get; } /// /// Gets the assembly name (short name). @@ -68,13 +80,15 @@ namespace ICSharpCode.Decompiler.TypeSystem /// /// Gets whether the internals of this assembly are visible in the specified assembly. /// - bool InternalsVisibleTo(IAssembly assembly); + bool InternalsVisibleTo(IModule module); /// - /// Gets the root namespace for this assembly. + /// Gets the root namespace for this module. /// /// /// This always is the namespace without a name - it's unrelated to the 'root namespace' project setting. + /// It contains only subnamespaces and types defined in this module -- use ICompilation.RootNamespace + /// to get the combined view of all referenced assemblies. /// INamespace RootNamespace { get; } diff --git a/ICSharpCode.Decompiler/TypeSystem/ICompilation.cs b/ICSharpCode.Decompiler/TypeSystem/ICompilation.cs index abd79c807..ebae2b04f 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ICompilation.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ICompilation.cs @@ -25,28 +25,30 @@ namespace ICSharpCode.Decompiler.TypeSystem public interface ICompilation { /// - /// Gets the current assembly. + /// Gets the primary module. + /// This is the module being (de)compiled; all other modules in the compilation are the other assemblies/modules + /// referenced by the main module. /// - IAssembly MainAssembly { get; } + IModule MainModule { get; } /// /// Gets the type resolve context that specifies this compilation and no current assembly or entity. /// ITypeResolveContext TypeResolveContext { get; } - + /// - /// Gets the list of all assemblies in the compilation. + /// Gets the list of all modules in the compilation. /// /// - /// This main assembly is the first entry in the list. + /// This main module is the first entry in the list. /// - IList Assemblies { get; } + IList Modules { get; } /// - /// Gets the referenced assemblies. - /// This list does not include the main assembly. + /// Gets the referenced modules. + /// This list does not include the main module. /// - IList ReferencedAssemblies { get; } + IList ReferencedModules { get; } /// /// Gets the root namespace of this compilation. diff --git a/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs b/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs index 714a500ce..ee02d6825 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs @@ -28,6 +28,7 @@ namespace ICSharpCode.Decompiler.TypeSystem public interface IDecompilerTypeSystem { ICompilation Compilation { get; } + MetadataModule MainModule { get; } MethodSignature DecodeMethodSignature(StandaloneSignatureHandle standaloneSignatureHandle); ImmutableArray DecodeLocalSignature(StandaloneSignatureHandle standaloneSignatureHandle); @@ -39,7 +40,6 @@ namespace ICSharpCode.Decompiler.TypeSystem MetadataReader GetMetadata(); PEFile ModuleDefinition { get; } - PEFile GetModuleDefinition(IAssembly assembly); /// /// Gets a type system instance that automatically specializes the results diff --git a/ICSharpCode.Decompiler/TypeSystem/IEntity.cs b/ICSharpCode.Decompiler/TypeSystem/IEntity.cs index 3c9cf7109..e80b9b9ad 100644 --- a/ICSharpCode.Decompiler/TypeSystem/IEntity.cs +++ b/ICSharpCode.Decompiler/TypeSystem/IEntity.cs @@ -56,10 +56,9 @@ namespace ICSharpCode.Decompiler.TypeSystem IType DeclaringType { get; } /// - /// The assembly in which this entity is defined. - /// This property never returns null. + /// The module in which this entity is defined. /// - IAssembly ParentAssembly { get; } + IModule ParentModule { get; } /// /// Gets the attributes on this entity. diff --git a/ICSharpCode.Decompiler/TypeSystem/INamespace.cs b/ICSharpCode.Decompiler/TypeSystem/INamespace.cs index 224a7acde..92907299f 100644 --- a/ICSharpCode.Decompiler/TypeSystem/INamespace.cs +++ b/ICSharpCode.Decompiler/TypeSystem/INamespace.cs @@ -62,9 +62,9 @@ namespace ICSharpCode.Decompiler.TypeSystem IEnumerable Types { get; } /// - /// Gets the assemblies that contribute types to this namespace (or to child namespaces). + /// Gets the modules that contribute types to this namespace (or to child namespaces). /// - IEnumerable ContributingAssemblies { get; } + IEnumerable ContributingModules { get; } /// /// Gets a direct child namespace by its short name. diff --git a/ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs b/ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs index 7d442051b..8a6dfe501 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs @@ -50,10 +50,10 @@ namespace ICSharpCode.Decompiler.TypeSystem public interface ITypeResolveContext : ICompilationProvider { /// - /// Gets the current assembly. - /// This property may return null if this context does not specify any assembly. + /// Gets the current module. + /// This property may return null if this context does not specify any module. /// - IAssembly CurrentAssembly { get; } + IModule CurrentModule { get; } /// /// Gets the current type definition. diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/AttributeListBuilder.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/AttributeListBuilder.cs index a9b6ea07c..a4e660282 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/AttributeListBuilder.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/AttributeListBuilder.cs @@ -32,20 +32,20 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { readonly struct AttributeListBuilder { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly List attributes; - public AttributeListBuilder(MetadataAssembly assembly) + public AttributeListBuilder(MetadataModule module) { - Debug.Assert(assembly != null); - this.assembly = assembly; + Debug.Assert(module != null); + this.module = module; this.attributes = new List(); } - public AttributeListBuilder(MetadataAssembly assembly, int capacity) + public AttributeListBuilder(MetadataModule module, int capacity) { - Debug.Assert(assembly != null); - this.assembly = assembly; + Debug.Assert(module != null); + this.module = module; this.attributes = new List(capacity); } @@ -60,7 +60,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public void Add(KnownAttribute type) { // use the assemblies' cache for simple attributes - Add(assembly.MakeAttribute(type)); + Add(module.MakeAttribute(type)); } /// @@ -68,7 +68,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// public void Add(KnownAttribute type, KnownTypeCode argType, object argValue) { - Add(type, ImmutableArray.Create(new CustomAttributeTypedArgument(assembly.Compilation.FindType(argType), argValue))); + Add(type, ImmutableArray.Create(new CustomAttributeTypedArgument(module.Compilation.FindType(argType), argValue))); } /// @@ -76,7 +76,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// public void Add(KnownAttribute type, TopLevelTypeName argType, object argValue) { - Add(type, ImmutableArray.Create(new CustomAttributeTypedArgument(assembly.Compilation.FindType(argType), argValue))); + Add(type, ImmutableArray.Create(new CustomAttributeTypedArgument(module.Compilation.FindType(argType), argValue))); } /// @@ -84,7 +84,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// public void Add(KnownAttribute type, ImmutableArray> fixedArguments) { - Add(new DefaultAttribute(assembly.GetAttributeType(type), fixedArguments, + Add(new DefaultAttribute(module.GetAttributeType(type), fixedArguments, ImmutableArray.Create>())); } @@ -92,7 +92,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation internal void AddMarshalInfo(BlobHandle marshalInfo) { if (marshalInfo.IsNil) return; - var metadata = assembly.metadata; + var metadata = module.metadata; Add(ConvertMarshalInfo(metadata.GetBlobReader(marshalInfo))); } @@ -100,8 +100,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation IAttribute ConvertMarshalInfo(SRM.BlobReader marshalInfo) { - var b = new AttributeBuilder(assembly, KnownAttribute.MarshalAs); - IType unmanagedTypeType = assembly.Compilation.FindType(new TopLevelTypeName(InteropServices, nameof(UnmanagedType))); + var b = new AttributeBuilder(module, KnownAttribute.MarshalAs); + IType unmanagedTypeType = module.Compilation.FindType(new TopLevelTypeName(InteropServices, nameof(UnmanagedType))); int type = marshalInfo.ReadByte(); b.AddFixedArg(unmanagedTypeType, type); @@ -170,15 +170,15 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation #region Custom Attributes (ReadAttribute) public void Add(CustomAttributeHandleCollection attributes) { - var metadata = assembly.metadata; + var metadata = module.metadata; foreach (var handle in attributes) { var attribute = metadata.GetCustomAttribute(handle); - var ctor = assembly.ResolveMethod(attribute.Constructor); + var ctor = module.ResolveMethod(attribute.Constructor); var type = ctor.DeclaringType; if (IgnoreAttribute(type)) { continue; } - Add(new CustomAttribute(assembly, ctor, handle)); + Add(new CustomAttribute(module, ctor, handle)); } } @@ -188,7 +188,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return false; switch (attributeType.Namespace) { case "System.Runtime.CompilerServices": - var options = assembly.TypeSystemOptions; + var options = module.TypeSystemOptions; switch (attributeType.Name) { case "DynamicAttribute": return (options & TypeSystemOptions.Dynamic) != 0; @@ -212,7 +212,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation #region Security Attributes public void AddSecurityAttributes(DeclarativeSecurityAttributeHandleCollection securityDeclarations) { - var metadata = assembly.metadata; + var metadata = module.metadata; foreach (var secDecl in securityDeclarations) { if (secDecl.IsNil) continue; @@ -222,9 +222,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public void AddSecurityAttributes(DeclarativeSecurityAttribute secDecl) { - var securityActionType = assembly.Compilation.FindType(new TopLevelTypeName("System.Security.Permissions", "SecurityAction")); + var securityActionType = module.Compilation.FindType(new TopLevelTypeName("System.Security.Permissions", "SecurityAction")); var securityAction = new CustomAttributeTypedArgument(securityActionType, (int)secDecl.Action); - var metadata = assembly.metadata; + var metadata = module.metadata; var reader = metadata.GetBlobReader(secDecl.PermissionSet); if (reader.ReadByte() == '.') { // binary attribute @@ -242,7 +242,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation private void ReadXmlSecurityAttribute(ref SRM.BlobReader reader, CustomAttributeTypedArgument securityAction) { string xml = reader.ReadUTF16(reader.RemainingBytes); - var b = new AttributeBuilder(assembly, KnownAttribute.PermissionSet); + var b = new AttributeBuilder(module, KnownAttribute.PermissionSet); b.AddFixedArg(securityAction); b.AddNamedArg("XML", KnownTypeCode.String, xml); } @@ -250,13 +250,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation private IAttribute ReadBinarySecurityAttribute(ref SRM.BlobReader reader, CustomAttributeTypedArgument securityAction) { string attributeTypeName = reader.ReadSerializedString(); - IType attributeType = assembly.TypeProvider.GetTypeFromSerializedName(attributeTypeName); + IType attributeType = module.TypeProvider.GetTypeFromSerializedName(attributeTypeName); reader.ReadCompressedInteger(); // ?? // The specification seems to be incorrect here, so I'm using the logic from Cecil instead. int numNamed = reader.ReadCompressedInteger(); - var decoder = new Metadata.CustomAttributeDecoder(assembly.TypeProvider, assembly.metadata); + var decoder = new Metadata.CustomAttributeDecoder(module.TypeProvider, module.metadata); var namedArgs = decoder.DecodeNamedArguments(ref reader, numNamed); return new DefaultAttribute( @@ -282,14 +282,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation ImmutableArray>.Builder fixedArgs; ImmutableArray>.Builder namedArgs; - public AttributeBuilder(MetadataAssembly assembly, KnownAttribute attributeType) - : this(assembly, assembly.GetAttributeType(attributeType)) + public AttributeBuilder(MetadataModule module, KnownAttribute attributeType) + : this(module, module.GetAttributeType(attributeType)) { } - public AttributeBuilder(MetadataAssembly assembly, IType attributeType) + public AttributeBuilder(MetadataModule module, IType attributeType) { - this.compilation = assembly.Compilation; + this.compilation = module.Compilation; this.attributeType = attributeType; this.fixedArgs = ImmutableArray.CreateBuilder>(); this.namedArgs = ImmutableArray.CreateBuilder>(); diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs index 33048c775..ddff24541 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs @@ -34,7 +34,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// sealed class CustomAttribute : IAttribute { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly SRM.CustomAttributeHandle handle; public IMethod Constructor { get; } @@ -42,12 +42,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation SRM.CustomAttributeValue value; bool valueDecoded; - internal CustomAttribute(MetadataAssembly assembly, IMethod attrCtor, SRM.CustomAttributeHandle handle) + internal CustomAttribute(MetadataModule module, IMethod attrCtor, SRM.CustomAttributeHandle handle) { - Debug.Assert(assembly != null); + Debug.Assert(module != null); Debug.Assert(attrCtor != null); Debug.Assert(!handle.IsNil); - this.assembly = assembly; + this.module = module; this.Constructor = attrCtor; this.handle = handle; } @@ -72,9 +72,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { lock (this) { if (!valueDecoded) { - var metadata = assembly.metadata; + var metadata = module.metadata; var attr = metadata.GetCustomAttribute(handle); - value = attr.DecodeValue(assembly.TypeProvider); + value = attr.DecodeValue(module.TypeProvider); valueDecoded = true; } } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultAssemblyReference.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultAssemblyReference.cs index b9610e96c..2103fbf3e 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultAssemblyReference.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultAssemblyReference.cs @@ -24,9 +24,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// References an existing assembly by name. /// [Serializable] - public sealed class DefaultAssemblyReference : IAssemblyReference, ISupportsInterning + public sealed class DefaultAssemblyReference : IModuleReference, ISupportsInterning { - public static readonly IAssemblyReference CurrentAssembly = new CurrentAssemblyReference(); + public static readonly IModuleReference CurrentAssembly = new CurrentModuleReference(); readonly string shortName; @@ -39,12 +39,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation shortName = assemblyName; } - public IAssembly Resolve(ITypeResolveContext context) + public IModule Resolve(ITypeResolveContext context) { - IAssembly current = context.CurrentAssembly; + IModule current = context.CurrentModule; if (current != null && string.Equals(shortName, current.AssemblyName, StringComparison.OrdinalIgnoreCase)) return current; - foreach (IAssembly asm in context.Compilation.Assemblies) { + foreach (IModule asm in context.Compilation.Modules) { if (string.Equals(shortName, asm.AssemblyName, StringComparison.OrdinalIgnoreCase)) return asm; } @@ -70,11 +70,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation } [Serializable] - sealed class CurrentAssemblyReference : IAssemblyReference + sealed class CurrentModuleReference : IModuleReference { - public IAssembly Resolve(ITypeResolveContext context) + public IModule Resolve(ITypeResolveContext context) { - IAssembly asm = context.CurrentAssembly; + IModule asm = context.CurrentModule; if (asm == null) throw new ArgumentException("A reference to the current assembly cannot be resolved in the compilation's global type resolve context."); return asm; diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs index 2c71b660a..374413d70 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs @@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public IType DeclaringType { get; set; } - IAssembly IEntity.ParentAssembly => DeclaringType?.GetDefinition()?.ParentAssembly; + IModule IEntity.ParentModule => DeclaringType?.GetDefinition()?.ParentModule; IEnumerable IEntity.GetAttributes() => EmptyList.Instance; diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/GetClassTypeReference.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/GetClassTypeReference.cs index c934e2ff9..4c0aa3b3a 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/GetClassTypeReference.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/GetClassTypeReference.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation [Serializable] public sealed class GetClassTypeReference : ITypeReference, ISupportsInterning { - readonly IAssemblyReference assembly; + readonly IModuleReference module; readonly FullTypeName fullTypeName; readonly bool? isReferenceType; @@ -34,14 +34,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// Creates a new GetClassTypeReference that searches a type definition. /// /// The full name of the type. - /// A reference to the assembly containing this type. + /// A reference to the module containing this type. /// If this parameter is null, the GetClassTypeReference will search in all /// assemblies belonging to the compilation. /// - public GetClassTypeReference(FullTypeName fullTypeName, IAssemblyReference assembly = null, bool? isReferenceType = null) + public GetClassTypeReference(FullTypeName fullTypeName, IModuleReference module = null, bool? isReferenceType = null) { this.fullTypeName = fullTypeName; - this.assembly = assembly; + this.module = module; this.isReferenceType = isReferenceType; } @@ -60,14 +60,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// /// Creates a new GetClassTypeReference that searches a top-level type in the specified assembly. /// - /// A reference to the assembly containing this type. + /// A reference to the assembly containing this type. /// If this parameter is null, the GetClassTypeReference will search in all assemblies belonging to the ICompilation. /// The namespace name containing the type, e.g. "System.Collections.Generic". /// The name of the type, e.g. "List". /// The number of type parameters, (e.g. 1 for List<T>). - public GetClassTypeReference(IAssemblyReference assembly, string namespaceName, string name, int typeParameterCount = 0, bool? isReferenceType = null) + public GetClassTypeReference(IModuleReference module, string namespaceName, string name, int typeParameterCount = 0, bool? isReferenceType = null) { - this.assembly = assembly; + this.module = module; this.fullTypeName = new TopLevelTypeName(namespaceName, name, typeParameterCount); this.isReferenceType = isReferenceType; } @@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// This property returns null if the GetClassTypeReference is searching in all assemblies /// of the compilation. /// - public IAssemblyReference Assembly { get { return assembly; } } + public IModuleReference Module { get { return module; } } /// /// Gets the full name of the type this reference is searching for. @@ -87,7 +87,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation IType ResolveInAllAssemblies(ITypeResolveContext context) { var compilation = context.Compilation; - foreach (var asm in compilation.Assemblies) { + foreach (var asm in compilation.Modules) { IType type = asm.GetTypeDefinition(fullTypeName); if (type != null) return type; @@ -101,10 +101,10 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation throw new ArgumentNullException("context"); IType type = null; - if (assembly == null) { + if (module == null) { // No assembly specified: look in all assemblies, but prefer the current assembly - if (context.CurrentAssembly != null) { - type = context.CurrentAssembly.GetTypeDefinition(fullTypeName); + if (context.CurrentModule != null) { + type = context.CurrentModule.GetTypeDefinition(fullTypeName); } if (type == null) { type = ResolveInAllAssemblies(context); @@ -114,7 +114,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation // But if that's not loaded in the compilation, allow fall back to other assemblies. // (the non-loaded assembly might be a facade containing type forwarders - // for example, when referencing a portable library from a non-portable project) - IAssembly asm = assembly.Resolve(context); + IModule asm = module.Resolve(context); if (asm != null) { type = asm.GetTypeDefinition(fullTypeName); } else { @@ -126,20 +126,20 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override string ToString() { - return fullTypeName.ToString() + (assembly != null ? ", " + assembly.ToString() : null); + return fullTypeName.ToString() + (module != null ? ", " + module.ToString() : null); } int ISupportsInterning.GetHashCodeForInterning() { unchecked { - return 33 * assembly.GetHashCode() + fullTypeName.GetHashCode(); + return 33 * module.GetHashCode() + fullTypeName.GetHashCode(); } } bool ISupportsInterning.EqualsForInterning(ISupportsInterning other) { GetClassTypeReference o = other as GetClassTypeReference; - return o != null && assembly == o.assembly && fullTypeName == o.fullTypeName && isReferenceType == o.isReferenceType; + return o != null && module == o.module && fullTypeName == o.fullTypeName && isReferenceType == o.isReferenceType; } } } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/KnownTypeCache.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/KnownTypeCache.cs index f610de230..242bbb6a9 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/KnownTypeCache.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/KnownTypeCache.cs @@ -48,7 +48,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation if (typeRef == null) return SpecialType.UnknownType; var typeName = new TopLevelTypeName(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount); - foreach (IAssembly asm in compilation.Assemblies) { + foreach (IModule asm in compilation.Modules) { var typeDef = asm.GetTypeDefinition(typeName); if (typeDef != null) return typeDef; diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MergedNamespace.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MergedNamespace.cs index fec4c1bcf..f6b5e3508 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MergedNamespace.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MergedNamespace.cs @@ -99,8 +99,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation get { return compilation; } } - public IEnumerable ContributingAssemblies { - get { return namespaces.SelectMany(ns => ns.ContributingAssemblies); } + public IEnumerable ContributingModules { + get { return namespaces.SelectMany(ns => ns.ContributingModules); } } public IEnumerable ChildNamespaces { diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs index 674dad4cc..92cf56448 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { sealed class MetadataEvent : IEvent { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly EventDefinitionHandle handle; readonly EventAccessors accessors; readonly string name; @@ -40,14 +40,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation // lazy-loaded: IType returnType; - internal MetadataEvent(MetadataAssembly assembly, EventDefinitionHandle handle) + internal MetadataEvent(MetadataModule module, EventDefinitionHandle handle) { - Debug.Assert(assembly != null); + Debug.Assert(module != null); Debug.Assert(!handle.IsNil); - this.assembly = assembly; + this.module = module; this.handle = handle; - var metadata = assembly.metadata; + var metadata = module.metadata; var ev = metadata.GetEventDefinition(handle); accessors = ev.GetAccessors(); name = metadata.GetString(ev.Name); @@ -66,10 +66,10 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public bool CanAdd => !accessors.Adder.IsNil; public bool CanRemove => !accessors.Remover.IsNil; public bool CanInvoke => !accessors.Raiser.IsNil; - public IMethod AddAccessor => assembly.GetDefinition(accessors.Adder); - public IMethod RemoveAccessor => assembly.GetDefinition(accessors.Remover); - public IMethod InvokeAccessor => assembly.GetDefinition(accessors.Raiser); - IMethod AnyAccessor => assembly.GetDefinition(accessors.GetAny()); + public IMethod AddAccessor => module.GetDefinition(accessors.Adder); + public IMethod RemoveAccessor => module.GetDefinition(accessors.Remover); + public IMethod InvokeAccessor => module.GetDefinition(accessors.Raiser); + IMethod AnyAccessor => module.GetDefinition(accessors.GetAny()); #region Signature (ReturnType + Parameters) public IType ReturnType { @@ -77,10 +77,10 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation var returnType = LazyInit.VolatileRead(ref this.returnType); if (returnType != null) return returnType; - var metadata = assembly.metadata; + var metadata = module.metadata; var ev = metadata.GetEventDefinition(handle); var context = new GenericContext(DeclaringTypeDefinition?.TypeParameters); - returnType = assembly.ResolveType(ev.Type, context, ev.GetCustomAttributes()); + returnType = module.ResolveType(ev.Type, context, ev.GetCustomAttributes()); return LazyInit.GetOrSet(ref this.returnType, returnType); } } @@ -104,8 +104,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation #region Attributes public IEnumerable GetAttributes() { - var b = new AttributeListBuilder(assembly); - var metadata = assembly.metadata; + var b = new AttributeListBuilder(module); + var metadata = module.metadata; var eventDef = metadata.GetEventDefinition(handle); b.Add(eventDef.GetCustomAttributes()); return b.Build(); @@ -120,8 +120,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public bool IsOverride => AnyAccessor?.IsOverride ?? false; public bool IsOverridable => AnyAccessor?.IsOverridable ?? false; - public IAssembly ParentAssembly => assembly; - public ICompilation Compilation => assembly.Compilation; + public IModule ParentModule => module; + public ICompilation Compilation => module.Compilation; public string FullName => $"{DeclaringType?.FullName}.{Name}"; public string ReflectionName => $"{DeclaringType?.ReflectionName}.{Name}"; @@ -130,14 +130,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override bool Equals(object obj) { if (obj is MetadataEvent ev) { - return handle == ev.handle && assembly.PEFile == ev.assembly.PEFile; + return handle == ev.handle && module.PEFile == ev.module.PEFile; } return false; } public override int GetHashCode() { - return 0x7937039a ^ assembly.PEFile.GetHashCode() ^ handle.GetHashCode(); + return 0x7937039a ^ module.PEFile.GetHashCode() ^ handle.GetHashCode(); } bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs index e5dacfb4b..d7c942730 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// sealed class MetadataField : IField { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly FieldDefinitionHandle handle; readonly FieldAttributes attributes; @@ -44,13 +44,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation bool isVolatile; // initialized together with this.type byte decimalConstant; // 0=no, 1=yes, 2=unknown - internal MetadataField(MetadataAssembly assembly, FieldDefinitionHandle handle) + internal MetadataField(MetadataModule module, FieldDefinitionHandle handle) { - Debug.Assert(assembly != null); + Debug.Assert(module != null); Debug.Assert(!handle.IsNil); - this.assembly = assembly; + this.module = module; this.handle = handle; - var def = assembly.metadata.GetFieldDefinition(handle); + var def = module.metadata.GetFieldDefinition(handle); this.attributes = def.Attributes; if ((attributes & (FieldAttributes.Static | FieldAttributes.InitOnly)) == (FieldAttributes.Static | FieldAttributes.InitOnly)) { decimalConstant = 2; // may be decimal constant @@ -69,7 +69,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation string name = LazyInit.VolatileRead(ref this.name); if (name != null) return name; - var metadata = assembly.metadata; + var metadata = module.metadata; var fieldDef = metadata.GetFieldDefinition(handle); return LazyInit.GetOrSet(ref this.name, metadata.GetString(fieldDef.Name)); } @@ -116,21 +116,21 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation if (declType != null) { return declType; } else { - var def = assembly.metadata.GetFieldDefinition(handle); + var def = module.metadata.GetFieldDefinition(handle); return LazyInit.GetOrSet(ref this.declaringType, - assembly.GetDefinition(def.GetDeclaringType())); + module.GetDefinition(def.GetDeclaringType())); } } } public IType DeclaringType => DeclaringTypeDefinition; - public IAssembly ParentAssembly => assembly; - public ICompilation Compilation => assembly.Compilation; + public IModule ParentModule => module; + public ICompilation Compilation => module.Compilation; public IEnumerable GetAttributes() { - var b = new AttributeListBuilder(assembly); - var metadata = assembly.metadata; + var b = new AttributeListBuilder(module); + var metadata = module.metadata; var fieldDef = metadata.GetFieldDefinition(handle); // FieldOffsetAttribute @@ -175,15 +175,15 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation private IType DecodeTypeAndVolatileFlag() { - var metadata = assembly.metadata; + var metadata = module.metadata; var fieldDef = metadata.GetFieldDefinition(handle); - var ty = fieldDef.DecodeSignature(assembly.TypeProvider, new GenericContext(DeclaringType?.TypeParameters)); + var ty = fieldDef.DecodeSignature(module.TypeProvider, new GenericContext(DeclaringType?.TypeParameters)); if (ty is ModifiedType mod && mod.Modifier.Name == "IsVolatile" && mod.Modifier.Namespace == "System.Runtime.CompilerServices") { Volatile.Write(ref this.isVolatile, true); ty = mod.ElementType; } ty = ApplyAttributeTypeVisitor.ApplyAttributesToType(ty, Compilation, - fieldDef.GetCustomAttributes(), metadata, assembly.TypeSystemOptions); + fieldDef.GetCustomAttributes(), metadata, module.TypeSystemOptions); return LazyInit.GetOrSet(ref this.type, ty); } @@ -192,7 +192,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation bool IsDecimalConstant { get { if (decimalConstant == 2) { - var metadata = assembly.metadata; + var metadata = module.metadata; var fieldDef = metadata.GetFieldDefinition(handle); if (fieldDef.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.DecimalConstant)) decimalConstant = 1; @@ -208,7 +208,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation object val = LazyInit.VolatileRead(ref this.constantValue); if (val != null) return val; - var metadata = assembly.metadata; + var metadata = module.metadata; var fieldDef = metadata.GetFieldDefinition(handle); if (IsDecimalConstant) { foreach (var attrHandle in fieldDef.GetCustomAttributes()) { @@ -231,7 +231,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation decimal? TryDecodeDecimalConstantAttribute(System.Reflection.Metadata.CustomAttribute attribute) { - var attrValue = attribute.DecodeValue(assembly.TypeProvider); + var attrValue = attribute.DecodeValue(module.TypeProvider); if (attrValue.FixedArguments.Length != 5) return null; // DecimalConstantAttribute has the arguments (byte scale, byte sign, uint hi, uint mid, uint low) or (byte scale, byte sign, int hi, int mid, int low) @@ -258,14 +258,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override bool Equals(object obj) { if (obj is MetadataField f) { - return handle == f.handle && assembly.PEFile == f.assembly.PEFile; + return handle == f.handle && module.PEFile == f.module.PEFile; } return false; } public override int GetHashCode() { - return 0x11dda32b ^ assembly.PEFile.GetHashCode() ^ handle.GetHashCode(); + return 0x11dda32b ^ module.PEFile.GetHashCode() ^ handle.GetHashCode(); } bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs index f3e3b43ce..7fad092ca 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { sealed class MetadataMethod : IMethod { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly MethodDefinitionHandle handle; // eagerly loaded fields: @@ -48,18 +48,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation IParameter[] parameters; IType returnType; - internal MetadataMethod(MetadataAssembly assembly, MethodDefinitionHandle handle) + internal MetadataMethod(MetadataModule module, MethodDefinitionHandle handle) { - Debug.Assert(assembly != null); + Debug.Assert(module != null); Debug.Assert(!handle.IsNil); - this.assembly = assembly; + this.module = module; this.handle = handle; - var metadata = assembly.metadata; + var metadata = module.metadata; var def = metadata.GetMethodDefinition(handle); this.attributes = def.Attributes; this.symbolKind = SymbolKind.Method; - var (accessorOwner, semanticsAttribute) = assembly.PEFile.MethodSemanticsLookup.GetSemantics(handle); + var (accessorOwner, semanticsAttribute) = module.PEFile.MethodSemanticsLookup.GetSemantics(handle); if (semanticsAttribute != 0) { this.symbolKind = SymbolKind.Accessor; this.accessorOwner = accessorOwner; @@ -70,9 +70,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation else if (name.StartsWith("op_", StringComparison.Ordinal)) this.symbolKind = SymbolKind.Operator; } - this.typeParameters = MetadataTypeParameter.Create(assembly, this, def.GetGenericParameters()); + this.typeParameters = MetadataTypeParameter.Create(module, this, def.GetGenericParameters()); this.IsExtensionMethod = (attributes & MethodAttributes.Static) == MethodAttributes.Static - && (assembly.TypeSystemOptions & TypeSystemOptions.ExtensionMethods) == TypeSystemOptions.ExtensionMethods + && (module.TypeSystemOptions & TypeSystemOptions.ExtensionMethods) == TypeSystemOptions.ExtensionMethods && def.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.Extension); } @@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation string name = LazyInit.VolatileRead(ref this.name); if (name != null) return name; - var metadata = assembly.metadata; + var metadata = module.metadata; var methodDef = metadata.GetMethodDefinition(handle); return LazyInit.GetOrSet(ref this.name, metadata.GetString(methodDef.Name)); } @@ -103,7 +103,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public bool IsOperator => symbolKind == SymbolKind.Operator; public bool IsAccessor => symbolKind == SymbolKind.Accessor; - public bool HasBody => assembly.metadata.GetMethodDefinition(handle).HasBody(); + public bool HasBody => module.metadata.GetMethodDefinition(handle).HasBody(); public IMember AccessorOwner { @@ -111,9 +111,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation if (accessorOwner.IsNil) return null; if (accessorOwner.Kind == HandleKind.PropertyDefinition) - return assembly.GetDefinition((PropertyDefinitionHandle)accessorOwner); + return module.GetDefinition((PropertyDefinitionHandle)accessorOwner); else if (accessorOwner.Kind == HandleKind.EventDefinition) - return assembly.GetDefinition((EventDefinitionHandle)accessorOwner); + return module.GetDefinition((EventDefinitionHandle)accessorOwner); else return null; } @@ -142,17 +142,17 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation private void DecodeSignature() { - var methodDef = assembly.metadata.GetMethodDefinition(handle); + var methodDef = module.metadata.GetMethodDefinition(handle); var genericContext = new GenericContext(DeclaringType.TypeParameters, this.TypeParameters); - var signature = methodDef.DecodeSignature(assembly.TypeProvider, genericContext); - var (returnType, parameters) = DecodeSignature(assembly, this, signature, methodDef.GetParameters()); + var signature = methodDef.DecodeSignature(module.TypeProvider, genericContext); + var (returnType, parameters) = DecodeSignature(module, this, signature, methodDef.GetParameters()); LazyInit.GetOrSet(ref this.returnType, returnType); LazyInit.GetOrSet(ref this.parameters, parameters); } - internal static (IType, IParameter[]) DecodeSignature(MetadataAssembly assembly, IParameterizedMember owner, MethodSignature signature, ParameterHandleCollection? parameterHandles) + internal static (IType, IParameter[]) DecodeSignature(MetadataModule module, IParameterizedMember owner, MethodSignature signature, ParameterHandleCollection? parameterHandles) { - var metadata = assembly.metadata; + var metadata = module.metadata; int i = 0; CustomAttributeHandleCollection? returnTypeAttributes = null; IParameter[] parameters = new IParameter[signature.RequiredParameterCount @@ -166,16 +166,16 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation } else if (par.SequenceNumber > 0 && i < signature.RequiredParameterCount) { Debug.Assert(par.SequenceNumber - 1 == i); var parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( - signature.ParameterTypes[i], assembly.Compilation, - par.GetCustomAttributes(), metadata, assembly.TypeSystemOptions); - parameters[i] = new MetadataParameter(assembly, owner, parameterType, parameterHandle); + signature.ParameterTypes[i], module.Compilation, + par.GetCustomAttributes(), metadata, module.TypeSystemOptions); + parameters[i] = new MetadataParameter(module, owner, parameterType, parameterHandle); i++; } } } while (i < signature.RequiredParameterCount) { var parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( - signature.ParameterTypes[i], assembly.Compilation, null, metadata, assembly.TypeSystemOptions); + signature.ParameterTypes[i], module.Compilation, null, metadata, module.TypeSystemOptions); parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner, isRef: parameterType.Kind == TypeKind.ByReference); i++; @@ -186,7 +186,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation } Debug.Assert(i == parameters.Length); var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType, - assembly.Compilation, returnTypeAttributes, metadata, assembly.TypeSystemOptions); + module.Compilation, returnTypeAttributes, metadata, module.TypeSystemOptions); return (returnType, parameters); } #endregion @@ -217,38 +217,38 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation if (declType != null) { return declType; } else { - var def = assembly.metadata.GetMethodDefinition(handle); + var def = module.metadata.GetMethodDefinition(handle); return LazyInit.GetOrSet(ref this.declaringType, - assembly.GetDefinition(def.GetDeclaringType())); + module.GetDefinition(def.GetDeclaringType())); } } } public IType DeclaringType => DeclaringTypeDefinition; - public IAssembly ParentAssembly => assembly; - public ICompilation Compilation => assembly.Compilation; + public IModule ParentModule => module; + public ICompilation Compilation => module.Compilation; #region Attributes IType FindInteropType(string name) { - return assembly.Compilation.FindType(new TopLevelTypeName( + return module.Compilation.FindType(new TopLevelTypeName( "System.Runtime.InteropServices", name, 0 )); } public IEnumerable GetAttributes() { - var b = new AttributeListBuilder(assembly); + var b = new AttributeListBuilder(module); - var metadata = assembly.metadata; + var metadata = module.metadata; var def = metadata.GetMethodDefinition(handle); MethodImplAttributes implAttributes = def.ImplAttributes & ~MethodImplAttributes.CodeTypeMask; #region DllImportAttribute var info = def.GetImport(); if ((attributes & MethodAttributes.PinvokeImpl) == MethodAttributes.PinvokeImpl && !info.Module.IsNil) { - var dllImport = new AttributeBuilder(assembly, KnownAttribute.DllImport); + var dllImport = new AttributeBuilder(module, KnownAttribute.DllImport); dllImport.AddFixedArg(KnownTypeCode.String, metadata.GetString(metadata.GetModuleReference(info.Module).Name)); @@ -356,8 +356,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation #region Return type attributes public IEnumerable GetReturnTypeAttributes() { - var b = new AttributeListBuilder(assembly); - var metadata = assembly.metadata; + var b = new AttributeListBuilder(module); + var metadata = module.metadata; var methodDefinition = metadata.GetMethodDefinition(handle); var parameters = methodDefinition.GetParameters(); if (parameters.Count > 0) { @@ -409,14 +409,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override bool Equals(object obj) { if (obj is MetadataMethod m) { - return handle == m.handle && assembly.PEFile == m.assembly.PEFile; + return handle == m.handle && module.PEFile == m.module.PEFile; } return false; } public override int GetHashCode() { - return 0x5a00d671 ^ assembly.PEFile.GetHashCode() ^ handle.GetHashCode(); + return 0x5a00d671 ^ module.PEFile.GetHashCode() ^ handle.GetHashCode(); } bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataNamespace.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataNamespace.cs index af033365c..5d5d5052e 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataNamespace.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataNamespace.cs @@ -26,22 +26,22 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { sealed class MetadataNamespace : INamespace { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly NamespaceDefinition ns; public INamespace ParentNamespace { get; } public string FullName { get; } public string Name { get; } - public MetadataNamespace(MetadataAssembly assembly, INamespace parent, string fullName, NamespaceDefinition ns) + public MetadataNamespace(MetadataModule module, INamespace parent, string fullName, NamespaceDefinition ns) { - Debug.Assert(assembly != null); + Debug.Assert(module != null); Debug.Assert(fullName != null); - this.assembly = assembly; + this.module = module; this.ParentNamespace = parent; this.ns = ns; this.FullName = fullName; - this.Name = assembly.GetString(ns.Name); + this.Name = module.GetString(ns.Name); } string INamespace.ExternAlias => string.Empty; @@ -58,9 +58,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation children = new INamespace[nsDefs.Length]; for (int i = 0; i < children.Length; i++) { var nsHandle = nsDefs[i]; - string fullName = assembly.metadata.GetString(nsHandle); - children[i] = new MetadataNamespace(assembly, this, fullName, - assembly.metadata.GetNamespaceDefinition(nsHandle)); + string fullName = module.metadata.GetString(nsHandle); + children[i] = new MetadataNamespace(module, this, fullName, + module.metadata.GetNamespaceDefinition(nsHandle)); } return LazyInit.GetOrSet(ref childNamespaces, children); } @@ -69,18 +69,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation IEnumerable INamespace.Types { get { foreach (var typeHandle in ns.TypeDefinitions) { - var def = assembly.GetDefinition(typeHandle); + var def = module.GetDefinition(typeHandle); if (def != null) yield return def; } } } - IEnumerable INamespace.ContributingAssemblies => new[] { assembly }; + IEnumerable INamespace.ContributingModules => new[] { module }; SymbolKind ISymbol.SymbolKind => SymbolKind.Namespace; - ICompilation ICompilationProvider.Compilation => assembly.Compilation; + ICompilation ICompilationProvider.Compilation => module.Compilation; INamespace INamespace.GetChildNamespace(string name) { @@ -93,7 +93,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation ITypeDefinition INamespace.GetTypeDefinition(string name, int typeParameterCount) { - return assembly.GetTypeDefinition(FullName, name, typeParameterCount); + return module.GetTypeDefinition(FullName, name, typeParameterCount); } } } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs index 7f2123a34..1dad96af7 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { sealed class MetadataParameter : IParameter { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly ParameterHandle handle; readonly ParameterAttributes attributes; @@ -38,14 +38,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation // lazy-loaded: string name; - internal MetadataParameter(MetadataAssembly assembly, IParameterizedMember owner, IType type, ParameterHandle handle) + internal MetadataParameter(MetadataModule module, IParameterizedMember owner, IType type, ParameterHandle handle) { - this.assembly = assembly; + this.module = module; this.Owner = owner; this.Type = type; this.handle = handle; - var param = assembly.metadata.GetParameter(handle); + var param = module.metadata.GetParameter(handle); this.attributes = param.Attributes; } @@ -54,8 +54,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation #region Attributes public IEnumerable GetAttributes() { - var b = new AttributeListBuilder(assembly); - var metadata = assembly.metadata; + var b = new AttributeListBuilder(module); + var metadata = module.metadata; var parameter = metadata.GetParameter(handle); if (!IsOut) { @@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation get { if (Type.Kind != TypeKind.Array) return false; - var metadata = assembly.metadata; + var metadata = module.metadata; var propertyDef = metadata.GetParameter(handle); return propertyDef.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.ParamArray); } @@ -91,7 +91,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation string name = LazyInit.VolatileRead(ref this.name); if (name != null) return name; - var metadata = assembly.metadata; + var metadata = module.metadata; var propertyDef = metadata.GetParameter(handle); return LazyInit.GetOrSet(ref this.name, metadata.GetString(propertyDef.Name)); } @@ -101,7 +101,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public object ConstantValue { get { - var metadata = assembly.metadata; + var metadata = module.metadata; var propertyDef = metadata.GetParameter(handle); var constantHandle = propertyDef.GetDefaultValue(); if (constantHandle.IsNil) diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs index 7817b301c..258ac899c 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs @@ -16,16 +16,11 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Reflection; using System.Reflection.Metadata; using System.Reflection.Metadata.Ecma335; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; -using ICSharpCode.Decompiler.Semantics; using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.TypeSystem.Implementation @@ -34,7 +29,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { const Accessibility InvalidAccessibility = (Accessibility)0xff; - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly PropertyDefinitionHandle propertyHandle; readonly IMethod getter; readonly IMethod setter; @@ -46,18 +41,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation IParameter[] parameters; IType returnType; - internal MetadataProperty(MetadataAssembly assembly, PropertyDefinitionHandle handle) + internal MetadataProperty(MetadataModule module, PropertyDefinitionHandle handle) { - Debug.Assert(assembly != null); + Debug.Assert(module != null); Debug.Assert(!handle.IsNil); - this.assembly = assembly; + this.module = module; this.propertyHandle = handle; - var metadata = assembly.metadata; + var metadata = module.metadata; var prop = metadata.GetPropertyDefinition(handle); var accessors = prop.GetAccessors(); - getter = assembly.GetDefinition(accessors.Getter); - setter = assembly.GetDefinition(accessors.Setter); + getter = module.GetDefinition(accessors.Getter); + setter = module.GetDefinition(accessors.Setter); name = metadata.GetString(prop.Name); if (name == (DeclaringTypeDefinition as MetadataTypeDefinition)?.DefaultMemberName) { symbolKind = SymbolKind.Indexer; @@ -111,18 +106,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation private void DecodeSignature() { - var propertyDef = assembly.metadata.GetPropertyDefinition(propertyHandle); + var propertyDef = module.metadata.GetPropertyDefinition(propertyHandle); var genericContext = new GenericContext(DeclaringType.TypeParameters); - var signature = propertyDef.DecodeSignature(assembly.TypeProvider, genericContext); + var signature = propertyDef.DecodeSignature(module.TypeProvider, genericContext); var accessors = propertyDef.GetAccessors(); ParameterHandleCollection? parameterHandles; if (!accessors.Getter.IsNil) - parameterHandles = assembly.metadata.GetMethodDefinition(accessors.Getter).GetParameters(); + parameterHandles = module.metadata.GetMethodDefinition(accessors.Getter).GetParameters(); else if (!accessors.Setter.IsNil) - parameterHandles = assembly.metadata.GetMethodDefinition(accessors.Setter).GetParameters(); + parameterHandles = module.metadata.GetMethodDefinition(accessors.Setter).GetParameters(); else parameterHandles = null; - var (returnType, parameters) = MetadataMethod.DecodeSignature(assembly, this, signature, parameterHandles); + var (returnType, parameters) = MetadataMethod.DecodeSignature(module, this, signature, parameterHandles); LazyInit.GetOrSet(ref this.returnType, returnType); LazyInit.GetOrSet(ref this.parameters, parameters); } @@ -146,8 +141,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation #region Attributes public IEnumerable GetAttributes() { - var b = new AttributeListBuilder(assembly); - var metadata = assembly.metadata; + var b = new AttributeListBuilder(module); + var metadata = module.metadata; var propertyDef = metadata.GetPropertyDefinition(propertyHandle); if (IsIndexer && Name != "Item" && !IsExplicitInterfaceImplementation) { b.Add(KnownAttribute.IndexerName, KnownTypeCode.String, Name); @@ -213,8 +208,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public bool IsOverride => AnyAccessor?.IsOverride ?? false; public bool IsOverridable => AnyAccessor?.IsOverridable ?? false; - public IAssembly ParentAssembly => assembly; - public ICompilation Compilation => assembly.Compilation; + public IModule ParentModule => module; + public ICompilation Compilation => module.Compilation; public string FullName => $"{DeclaringType?.FullName}.{Name}"; public string ReflectionName => $"{DeclaringType?.ReflectionName}.{Name}"; @@ -223,14 +218,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override bool Equals(object obj) { if (obj is MetadataProperty p) { - return propertyHandle == p.propertyHandle && assembly.PEFile == p.assembly.PEFile; + return propertyHandle == p.propertyHandle && module.PEFile == p.module.PEFile; } return false; } public override int GetHashCode() { - return 0x32b6a76c ^ assembly.PEFile.GetHashCode() ^ propertyHandle.GetHashCode(); + return 0x32b6a76c ^ module.PEFile.GetHashCode() ^ propertyHandle.GetHashCode(); } bool IMember.Equals(IMember obj, TypeVisitor typeNormalization) diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs index b9c581536..243a49540 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs @@ -37,7 +37,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// sealed class MetadataTypeDefinition : ITypeDefinition { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly TypeDefinitionHandle handle; // eagerly loaded: @@ -59,25 +59,25 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation List directBaseTypes; string defaultMemberName; - internal MetadataTypeDefinition(MetadataAssembly assembly, TypeDefinitionHandle handle) + internal MetadataTypeDefinition(MetadataModule module, TypeDefinitionHandle handle) { - Debug.Assert(assembly != null); + Debug.Assert(module != null); Debug.Assert(!handle.IsNil); - this.assembly = assembly; + this.module = module; this.handle = handle; - var metadata = assembly.metadata; + var metadata = module.metadata; var td = metadata.GetTypeDefinition(handle); this.attributes = td.Attributes; this.fullTypeName = td.GetFullTypeName(metadata); // Find DeclaringType + KnownTypeCode: if (fullTypeName.IsNested) { - this.DeclaringTypeDefinition = assembly.GetDefinition(td.GetDeclaringType()); + this.DeclaringTypeDefinition = module.GetDefinition(td.GetDeclaringType()); // Create type parameters: - this.TypeParameters = MetadataTypeParameter.Create(assembly, this.DeclaringTypeDefinition, this, td.GetGenericParameters()); + this.TypeParameters = MetadataTypeParameter.Create(module, this.DeclaringTypeDefinition, this, td.GetGenericParameters()); } else { // Create type parameters: - this.TypeParameters = MetadataTypeParameter.Create(assembly, this, td.GetGenericParameters()); + this.TypeParameters = MetadataTypeParameter.Create(module, this, td.GetGenericParameters()); var topLevelTypeName = fullTypeName.TopLevelTypeName; for (int i = 0; i < KnownTypeReference.KnownTypeCodeCount; i++) { @@ -93,7 +93,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation this.Kind = TypeKind.Interface; } else if (td.IsEnum(metadata, out var underlyingType)) { this.Kind = TypeKind.Enum; - this.EnumUnderlyingType = assembly.Compilation.FindType(underlyingType.ToKnownTypeCode()); + this.EnumUnderlyingType = module.Compilation.FindType(underlyingType.ToKnownTypeCode()); } else if (td.IsValueType(metadata)) { if (KnownTypeCode == KnownTypeCode.Void) { this.Kind = TypeKind.Void; @@ -121,11 +121,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation var nestedTypes = LazyInit.VolatileRead(ref this.nestedTypes); if (nestedTypes != null) return nestedTypes; - var metadata = assembly.metadata; + var metadata = module.metadata; var nestedTypeCollection = metadata.GetTypeDefinition(handle).GetNestedTypes(); var nestedTypeList = new List(nestedTypeCollection.Length); foreach (TypeDefinitionHandle h in nestedTypeCollection) { - nestedTypeList.Add(assembly.GetDefinition(h)); + nestedTypeList.Add(module.GetDefinition(h)); } return LazyInit.GetOrSet(ref this.nestedTypes, nestedTypeList.ToArray()); } @@ -147,14 +147,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation var fields = LazyInit.VolatileRead(ref this.fields); if (fields != null) return fields; - var metadata = assembly.metadata; + var metadata = module.metadata; var fieldCollection = metadata.GetTypeDefinition(handle).GetFields(); var fieldList = new List(fieldCollection.Count); foreach (FieldDefinitionHandle h in fieldCollection) { var field = metadata.GetFieldDefinition(h); var attr = field.Attributes; - if (assembly.IsVisible(attr) && (attr & FieldAttributes.SpecialName) == 0) { - fieldList.Add(assembly.GetDefinition(h)); + if (module.IsVisible(attr) && (attr & FieldAttributes.SpecialName) == 0) { + fieldList.Add(module.GetDefinition(h)); } } return LazyInit.GetOrSet(ref this.fields, fieldList.ToArray()); @@ -166,16 +166,16 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation var properties = LazyInit.VolatileRead(ref this.properties); if (properties != null) return properties; - var metadata = assembly.metadata; + var metadata = module.metadata; var propertyCollection = metadata.GetTypeDefinition(handle).GetProperties(); var propertyList = new List(propertyCollection.Count); foreach (PropertyDefinitionHandle h in propertyCollection) { var property = metadata.GetPropertyDefinition(h); var accessors = property.GetAccessors(); - bool getterVisible = !accessors.Getter.IsNil && assembly.IsVisible(metadata.GetMethodDefinition(accessors.Getter).Attributes); - bool setterVisible = !accessors.Setter.IsNil && assembly.IsVisible(metadata.GetMethodDefinition(accessors.Setter).Attributes); + bool getterVisible = !accessors.Getter.IsNil && module.IsVisible(metadata.GetMethodDefinition(accessors.Getter).Attributes); + bool setterVisible = !accessors.Setter.IsNil && module.IsVisible(metadata.GetMethodDefinition(accessors.Setter).Attributes); if (getterVisible || setterVisible) { - propertyList.Add(assembly.GetDefinition(h)); + propertyList.Add(module.GetDefinition(h)); } } return LazyInit.GetOrSet(ref this.properties, propertyList.ToArray()); @@ -187,7 +187,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation var events = LazyInit.VolatileRead(ref this.events); if (events != null) return events; - var metadata = assembly.metadata; + var metadata = module.metadata; var eventCollection = metadata.GetTypeDefinition(handle).GetEvents(); var eventList = new List(eventCollection.Count); foreach (EventDefinitionHandle h in eventCollection) { @@ -196,8 +196,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation if (accessors.Adder.IsNil) continue; var addMethod = metadata.GetMethodDefinition(accessors.Adder); - if (assembly.IsVisible(addMethod.Attributes)) { - eventList.Add(assembly.GetDefinition(h)); + if (module.IsVisible(addMethod.Attributes)) { + eventList.Add(module.GetDefinition(h)); } } return LazyInit.GetOrSet(ref this.events, eventList.ToArray()); @@ -209,14 +209,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation var methods = LazyInit.VolatileRead(ref this.methods); if (methods != null) return methods; - var metadata = assembly.metadata; + var metadata = module.metadata; var methodsCollection = metadata.GetTypeDefinition(handle).GetMethods(); var methodsList = new List(methodsCollection.Count); - var methodSemantics = assembly.PEFile.MethodSemanticsLookup; + var methodSemantics = module.PEFile.MethodSemanticsLookup; foreach (MethodDefinitionHandle h in methodsCollection) { var md = metadata.GetMethodDefinition(h); - if (methodSemantics.GetSemantics(h).Item2 == 0 && assembly.IsVisible(md.Attributes)) { - methodsList.Add(assembly.GetDefinition(h)); + if (methodSemantics.GetSemantics(h).Item2 == 0 && module.IsVisible(md.Attributes)) { + methodsList.Add(module.GetDefinition(h)); } } if (this.Kind == TypeKind.Struct || this.Kind == TypeKind.Enum) { @@ -251,13 +251,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation var baseTypes = LazyInit.VolatileRead(ref this.directBaseTypes); if (baseTypes != null) return baseTypes; - var metadata = assembly.metadata; + var metadata = module.metadata; var td = metadata.GetTypeDefinition(handle); var context = new GenericContext(TypeParameters); var interfaceImplCollection = td.GetInterfaceImplementations(); baseTypes = new List(1 + interfaceImplCollection.Count); if (!td.BaseType.IsNil) { - baseTypes.Add(assembly.ResolveType(td.BaseType, context)); + baseTypes.Add(module.ResolveType(td.BaseType, context)); } else if (Kind == TypeKind.Interface) { // td.BaseType.IsNil is always true for interfaces, // but the type system expects every interface to derive from System.Object as well. @@ -265,7 +265,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation } foreach (var h in interfaceImplCollection) { var iface = metadata.GetInterfaceImplementation(h); - baseTypes.Add(assembly.ResolveType(iface.Interface, context, iface.GetCustomAttributes())); + baseTypes.Add(module.ResolveType(iface.Interface, context, iface.GetCustomAttributes())); } return LazyInit.GetOrSet(ref this.directBaseTypes, baseTypes); } @@ -276,13 +276,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public FullTypeName FullTypeName => fullTypeName; public string Name => fullTypeName.Name; - public IAssembly ParentAssembly => assembly; + public IModule ParentModule => module; #region Type Attributes public IEnumerable GetAttributes() { - var b = new AttributeListBuilder(assembly); - var metadata = assembly.metadata; + var b = new AttributeListBuilder(module); + var metadata = module.metadata; var typeDefinition = metadata.GetTypeDefinition(handle); // SerializableAttribute @@ -318,7 +318,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation var layout = typeDefinition.GetLayout(); LayoutKind defaultLayoutKind = Kind == TypeKind.Struct ? LayoutKind.Sequential : LayoutKind.Auto; if (layoutKind != defaultLayoutKind || charSet != CharSet.Ansi || layout.PackingSize > 0 || layout.Size > 0) { - var structLayout = new AttributeBuilder(assembly, KnownAttribute.StructLayout); + var structLayout = new AttributeBuilder(module, KnownAttribute.StructLayout); structLayout.AddFixedArg( new TopLevelTypeName("System.Runtime.InteropServices", "LayoutKind"), (int)layoutKind); @@ -347,13 +347,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation string defaultMemberName = LazyInit.VolatileRead(ref this.defaultMemberName); if (defaultMemberName != null) return defaultMemberName; - var metadata = assembly.metadata; + var metadata = module.metadata; var typeDefinition = metadata.GetTypeDefinition(handle); foreach (var h in typeDefinition.GetCustomAttributes()) { var a = metadata.GetCustomAttribute(h); if (!a.IsKnownAttribute(metadata, KnownAttribute.DefaultMember)) continue; - var value = a.DecodeValue(assembly.TypeProvider); + var value = a.DecodeValue(module.TypeProvider); if (value.FixedArguments.Length == 1 && value.FixedArguments[0].Value is string name) { defaultMemberName = name; break; @@ -393,7 +393,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public SymbolKind SymbolKind => SymbolKind.TypeDefinition; - public ICompilation Compilation => assembly.Compilation; + public ICompilation Compilation => module.Compilation; public string FullName { get { @@ -425,14 +425,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override bool Equals(object obj) { if (obj is MetadataTypeDefinition td) { - return handle == td.handle && assembly.PEFile == td.assembly.PEFile; + return handle == td.handle && module.PEFile == td.module.PEFile; } return false; } public override int GetHashCode() { - return 0x2e0520f2 ^ assembly.PEFile.GetHashCode() ^ handle.GetHashCode(); + return 0x2e0520f2 ^ module.PEFile.GetHashCode() ^ handle.GetHashCode(); } bool IEquatable.Equals(IType other) @@ -595,18 +595,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation #region GetOverrides internal IEnumerable GetOverrides(MethodDefinitionHandle method) { - var metadata = assembly.metadata; + var metadata = module.metadata; var td = metadata.GetTypeDefinition(handle); foreach (var implHandle in td.GetMethodImplementations()) { var impl = metadata.GetMethodImplementation(implHandle); if (impl.MethodBody == method) - yield return assembly.ResolveMethod(impl.MethodDeclaration, new GenericContext(this.TypeParameters)); + yield return module.ResolveMethod(impl.MethodDeclaration, new GenericContext(this.TypeParameters)); } } internal bool HasOverrides(MethodDefinitionHandle method) { - var metadata = assembly.metadata; + var metadata = module.metadata; var td = metadata.GetTypeDefinition(handle); foreach (var implHandle in td.GetMethodImplementations()) { var impl = metadata.GetMethodImplementation(implHandle); diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeParameter.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeParameter.cs index f0cf7326d..5c532d27d 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeParameter.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeParameter.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation { sealed class MetadataTypeParameter : AbstractTypeParameter { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly GenericParameterHandle handle; readonly GenericParameterAttributes attr; @@ -36,7 +36,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation // lazy-loaded: IReadOnlyList constraints; - public static ITypeParameter[] Create(MetadataAssembly assembly, ITypeDefinition copyFromOuter, IEntity owner, GenericParameterHandleCollection handles) + public static ITypeParameter[] Create(MetadataModule module, ITypeDefinition copyFromOuter, IEntity owner, GenericParameterHandleCollection handles) { if (handles.Count == 0) return Empty.Array; @@ -47,38 +47,38 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation if (i < outerTps.Count) tps[i] = outerTps[i]; else - tps[i] = Create(assembly, owner, i, handle); + tps[i] = Create(module, owner, i, handle); i++; } return tps; } - public static ITypeParameter[] Create(MetadataAssembly assembly, IEntity owner, GenericParameterHandleCollection handles) + public static ITypeParameter[] Create(MetadataModule module, IEntity owner, GenericParameterHandleCollection handles) { if (handles.Count == 0) return Empty.Array; var tps = new ITypeParameter[handles.Count]; int i = 0; foreach (var handle in handles) { - tps[i] = Create(assembly, owner, i, handle); + tps[i] = Create(module, owner, i, handle); i++; } return tps; } - public static MetadataTypeParameter Create(MetadataAssembly assembly, IEntity owner, int index, GenericParameterHandle handle) + public static MetadataTypeParameter Create(MetadataModule module, IEntity owner, int index, GenericParameterHandle handle) { - var metadata = assembly.metadata; + var metadata = module.metadata; var gp = metadata.GetGenericParameter(handle); Debug.Assert(gp.Index == index); - return new MetadataTypeParameter(assembly, owner, index, assembly.GetString(gp.Name), handle, gp.Attributes); + return new MetadataTypeParameter(module, owner, index, module.GetString(gp.Name), handle, gp.Attributes); } - private MetadataTypeParameter(MetadataAssembly assembly, IEntity owner, int index, string name, + private MetadataTypeParameter(MetadataModule module, IEntity owner, int index, string name, GenericParameterHandle handle, GenericParameterAttributes attr) : base(owner, index, name, GetVariance(attr)) { - this.assembly = assembly; + this.module = module; this.handle = handle; this.attr = attr; } @@ -99,11 +99,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override IEnumerable GetAttributes() { - var metadata = assembly.metadata; + var metadata = module.metadata; var gp = metadata.GetGenericParameter(handle); var attributes = gp.GetCustomAttributes(); - var b = new AttributeListBuilder(assembly, attributes.Count); + var b = new AttributeListBuilder(module, attributes.Count); b.Add(attributes); return b.Build(); } @@ -123,7 +123,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation private IReadOnlyList DecodeConstraints() { - var metadata = assembly.metadata; + var metadata = module.metadata; var gp = metadata.GetGenericParameter(handle); var constraintHandleCollection = gp.GetConstraints(); @@ -131,7 +131,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation bool hasNonInterfaceConstraint = false; foreach (var constraintHandle in constraintHandleCollection) { var constraint = metadata.GetGenericParameterConstraint(constraintHandle); - var ty = assembly.ResolveType(constraint.Type, new GenericContext(Owner), constraint.GetCustomAttributes()); + var ty = module.ResolveType(constraint.Type, new GenericContext(Owner), constraint.GetCustomAttributes()); result.Add(ty); hasNonInterfaceConstraint |= (ty.Kind != TypeKind.Interface); } @@ -145,12 +145,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override int GetHashCode() { - return 0x51fc5b83 ^ assembly.PEFile.GetHashCode() ^ handle.GetHashCode(); + return 0x51fc5b83 ^ module.PEFile.GetHashCode() ^ handle.GetHashCode(); } public override bool Equals(IType other) { - return other is MetadataTypeParameter tp && handle == tp.handle && assembly.PEFile == tp.assembly.PEFile; + return other is MetadataTypeParameter tp && handle == tp.handle && module.PEFile == tp.module.PEFile; } public override string ToString() diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs index 3b2ad26c5..dfadc4547 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs @@ -29,9 +29,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation /// An artificial "assembly" that contains all known types () and no other types. /// It does not contain any members. /// - public sealed class MinimalCorlib : IAssembly + public sealed class MinimalCorlib : IModule { - public static readonly IAssemblyReference Instance = new CorlibAssemblyReference(); + public static readonly IModuleReference Instance = new CorlibModuleReference(); public ICompilation Compilation { get; } CorlibTypeDefinition[] typeDefinitions; @@ -49,13 +49,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation } } - bool IAssembly.IsMainAssembly => Compilation.MainAssembly == this; + bool IModule.IsMainModule => Compilation.MainModule == this; - string IAssembly.AssemblyName => "corlib"; - string IAssembly.FullAssemblyName => "corlib"; + string IModule.AssemblyName => "corlib"; + string IModule.FullAssemblyName => "corlib"; - Metadata.PEFile IAssembly.PEFile => null; - INamespace IAssembly.RootNamespace => rootNamespace; + Metadata.PEFile IModule.PEFile => null; + INamespace IModule.RootNamespace => rootNamespace; public IEnumerable TopLevelTypeDefinitions => typeDefinitions.Where(td => td != null); public IEnumerable TypeDefinitions => TopLevelTypeDefinitions; @@ -69,17 +69,17 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return null; } - IEnumerable IAssembly.GetAssemblyAttributes() => EmptyList.Instance; - IEnumerable IAssembly.GetModuleAttributes() => EmptyList.Instance; + IEnumerable IModule.GetAssemblyAttributes() => EmptyList.Instance; + IEnumerable IModule.GetModuleAttributes() => EmptyList.Instance; - bool IAssembly.InternalsVisibleTo(IAssembly assembly) + bool IModule.InternalsVisibleTo(IModule module) { - return assembly == this; + return module == this; } - sealed class CorlibAssemblyReference : IAssemblyReference + sealed class CorlibModuleReference : IModuleReference { - IAssembly IAssemblyReference.Resolve(ITypeResolveContext context) + IModule IModuleReference.Resolve(ITypeResolveContext context) { return new MinimalCorlib(context.Compilation); } @@ -106,7 +106,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation IEnumerable INamespace.ChildNamespaces => childNamespaces; IEnumerable INamespace.Types => corlib.TopLevelTypeDefinitions.Where(td => td.Namespace == FullName); - IEnumerable INamespace.ContributingAssemblies => new[] { corlib }; + IEnumerable INamespace.ContributingModules => new[] { corlib }; SymbolKind ISymbol.SymbolKind => SymbolKind.Namespace; ICompilation ICompilationProvider.Compilation => corlib.Compilation; @@ -191,7 +191,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public string Name => KnownTypeReference.Get(typeCode).Name; - IAssembly IEntity.ParentAssembly => corlib; + IModule IEntity.ParentModule => corlib; Accessibility IEntity.Accessibility => Accessibility.Public; diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/TypeSpecification.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/PinnedType.cs similarity index 54% rename from ICSharpCode.Decompiler/TypeSystem/Implementation/TypeSpecification.cs rename to ICSharpCode.Decompiler/TypeSystem/Implementation/PinnedType.cs index 7951a5275..95b1efbc4 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/TypeSpecification.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/PinnedType.cs @@ -48,71 +48,4 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation return new PinnedType(newType); } } - - public sealed class PinnedTypeReference : ITypeReference - { - public ITypeReference ElementType { get; } - - public PinnedTypeReference(ITypeReference elementType) - { - ElementType = elementType; - } - - public IType Resolve(ITypeResolveContext context) - { - return new PinnedType(ElementType.Resolve(context)); - } - } - - public sealed class ModifiedTypeReference : ITypeReference - { - public ITypeReference ElementType { get; } - public ITypeReference ModifierType { get; } - public bool IsRequired { get; } - - public ModifiedTypeReference(ITypeReference elementType, ITypeReference modifierType, bool isRequired) - { - ElementType = elementType; - ModifierType = modifierType; - IsRequired = isRequired; - } - - public IType Resolve(ITypeResolveContext context) - { - return ElementType.Resolve(context); - } - } - - sealed class TypeDefTokenTypeReference : ITypeReference - { - readonly SRM.TypeDefinitionHandle token; - - public TypeDefTokenTypeReference(SRM.TypeDefinitionHandle token) - { - this.token = token; - } - - public IType Resolve(ITypeResolveContext context) - { - ITypeDefinition td = ((MetadataAssembly)context.CurrentAssembly).GetDefinition(token); - if (td != null) - return td; - return SpecialType.UnknownType; - } - } - - sealed class TypeSpecTypeReference : ITypeReference - { - readonly SRM.TypeSpecification typeSpec; - - public TypeSpecTypeReference(SRM.TypeSpecification typeSpec) - { - this.typeSpec = typeSpec; - } - - public IType Resolve(ITypeResolveContext context) - { - return typeSpec.DecodeSignature(new TypeProvider(context.CurrentAssembly), new GenericContext(context)); - } - } } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/SimpleCompilation.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/SimpleCompilation.cs index 8359a7947..365a2675f 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/SimpleCompilation.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/SimpleCompilation.cs @@ -30,29 +30,29 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation readonly ITypeResolveContext context; readonly CacheManager cacheManager = new CacheManager(); readonly KnownTypeCache knownTypeCache; - readonly IAssembly mainAssembly; - readonly IList assemblies; - readonly IList referencedAssemblies; + readonly IModule mainModule; + readonly IList assemblies; + readonly IList referencedAssemblies; INamespace rootNamespace; - public SimpleCompilation(IAssemblyReference mainAssembly, params IAssemblyReference[] assemblyReferences) - : this(mainAssembly, (IEnumerable)assemblyReferences) + public SimpleCompilation(IModuleReference mainAssembly, params IModuleReference[] assemblyReferences) + : this(mainAssembly, (IEnumerable)assemblyReferences) { } - public SimpleCompilation(IAssemblyReference mainAssembly, IEnumerable assemblyReferences) + public SimpleCompilation(IModuleReference mainAssembly, IEnumerable assemblyReferences) { if (mainAssembly == null) throw new ArgumentNullException("mainAssembly"); if (assemblyReferences == null) throw new ArgumentNullException("assemblyReferences"); this.context = new SimpleTypeResolveContext(this); - this.mainAssembly = mainAssembly.Resolve(context); - List assemblies = new List(); - assemblies.Add(this.mainAssembly); - List referencedAssemblies = new List(); + this.mainModule = mainAssembly.Resolve(context); + List assemblies = new List(); + assemblies.Add(this.mainModule); + List referencedAssemblies = new List(); foreach (var asmRef in assemblyReferences) { - IAssembly asm; + IModule asm; try { asm = asmRef.Resolve(context); } catch (InvalidOperationException) { @@ -68,15 +68,15 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation this.knownTypeCache = new KnownTypeCache(this); } - public IAssembly MainAssembly { + public IModule MainModule { get { - if (mainAssembly == null) + if (mainModule == null) throw new InvalidOperationException("Compilation isn't initialized yet"); - return mainAssembly; + return mainModule; } } - public IList Assemblies { + public IList Modules { get { if (assemblies == null) throw new InvalidOperationException("Compilation isn't initialized yet"); @@ -84,7 +84,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation } } - public IList ReferencedAssemblies { + public IList ReferencedModules { get { if (referencedAssemblies == null) throw new InvalidOperationException("Compilation isn't initialized yet"); @@ -114,7 +114,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation // SimpleCompilation does not support extern aliases; but derived classes might. // CreateRootNamespace() is virtual so that derived classes can change the global namespace. INamespace[] namespaces = new INamespace[referencedAssemblies.Count + 1]; - namespaces[0] = mainAssembly.RootNamespace; + namespaces[0] = mainModule.RootNamespace; for (int i = 0; i < referencedAssemblies.Count; i++) { namespaces[i + 1] = referencedAssemblies[i].RootNamespace; } @@ -144,7 +144,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation public override string ToString() { - return "[SimpleCompilation " + mainAssembly.AssemblyName + "]"; + return "[SimpleCompilation " + mainModule.AssemblyName + "]"; } } } diff --git a/ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMember.cs b/ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMember.cs index 79472bc5d..4498b5a98 100644 --- a/ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMember.cs +++ b/ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMember.cs @@ -201,8 +201,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation get { return baseMember.Compilation; } } - public IAssembly ParentAssembly { - get { return baseMember.ParentAssembly; } + public IModule ParentModule { + get { return baseMember.ParentModule; } } public virtual IMember Specialize(TypeParameterSubstitution newSubstitution) diff --git a/ICSharpCode.Decompiler/TypeSystem/MetadataAssembly.cs b/ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs similarity index 96% rename from ICSharpCode.Decompiler/TypeSystem/MetadataAssembly.cs rename to ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs index 65856285c..a17271e67 100644 --- a/ICSharpCode.Decompiler/TypeSystem/MetadataAssembly.cs +++ b/ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs @@ -31,11 +31,10 @@ using ICSharpCode.Decompiler.Util; namespace ICSharpCode.Decompiler.TypeSystem { /// - /// Used as context object for metadata TS entities; - /// should be turned into IAssembly implementation when the TS refactoring is complete. + /// Type system implementation for Metadata.PEFile. /// - [DebuggerDisplay("")] - public class MetadataAssembly : IAssembly + [DebuggerDisplay("")] + public class MetadataModule : IModule { public ICompilation Compilation { get; } internal readonly MetadataReader metadata; @@ -49,7 +48,7 @@ namespace ICSharpCode.Decompiler.TypeSystem readonly MetadataProperty[] propertyDefs; readonly MetadataEvent[] eventDefs; - internal MetadataAssembly(ICompilation compilation, Metadata.PEFile peFile, TypeSystemOptions options) + internal MetadataModule(ICompilation compilation, Metadata.PEFile peFile, TypeSystemOptions options) { this.Compilation = compilation; this.PEFile = peFile; @@ -87,7 +86,7 @@ namespace ICSharpCode.Decompiler.TypeSystem #region IAssembly interface public PEFile PEFile { get; } - public bool IsMainAssembly => this == Compilation.MainAssembly; + public bool IsMainModule => this == Compilation.MainModule; public string AssemblyName { get; } public string FullAssemblyName { get; } @@ -111,12 +110,12 @@ namespace ICSharpCode.Decompiler.TypeSystem #endregion #region InternalsVisibleTo - public bool InternalsVisibleTo(IAssembly assembly) + public bool InternalsVisibleTo(IModule module) { - if (this == assembly) + if (this == module) return true; foreach (string shortName in GetInternalsVisibleTo()) { - if (string.Equals(assembly.AssemblyName, shortName, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(module.AssemblyName, shortName, StringComparison.OrdinalIgnoreCase)) return true; } return false; @@ -572,13 +571,13 @@ namespace ICSharpCode.Decompiler.TypeSystem IType ResolveForwardedType(ExportedType forwarder) { - IAssembly assembly = ResolveAssembly(forwarder); + IModule module = ResolveModule(forwarder); var typeName = forwarder.GetFullTypeName(metadata); - if (assembly == null) + if (module == null) return new UnknownType(typeName); using (var busyLock = BusyManager.Enter(this)) { if (busyLock.Success) { - var td = assembly.GetTypeDefinition(typeName); + var td = module.GetTypeDefinition(typeName); if (td != null) { return td; } @@ -586,7 +585,7 @@ namespace ICSharpCode.Decompiler.TypeSystem } return new UnknownType(typeName); - IAssembly ResolveAssembly(ExportedType type) + IModule ResolveModule(ExportedType type) { switch (type.Implementation.Kind) { case HandleKind.AssemblyFile: @@ -594,11 +593,11 @@ namespace ICSharpCode.Decompiler.TypeSystem return this; case HandleKind.ExportedType: var outerType = metadata.GetExportedType((ExportedTypeHandle)type.Implementation); - return ResolveAssembly(outerType); + return ResolveModule(outerType); case HandleKind.AssemblyReference: var asmRef = metadata.GetAssemblyReference((AssemblyReferenceHandle)type.Implementation); string shortName = metadata.GetString(asmRef.Name); - foreach (var asm in Compilation.Assemblies) { + foreach (var asm in Compilation.Modules) { if (string.Equals(asm.AssemblyName, shortName, StringComparison.OrdinalIgnoreCase)) { return asm; } diff --git a/ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs b/ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs index 9f0b82f6f..16dbaa154 100644 --- a/ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs +++ b/ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs @@ -110,7 +110,7 @@ namespace ICSharpCode.Decompiler.TypeSystem string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount); return new NestedTypeReference(baseTypeRef, name, typeParameterCount); } else { - IAssemblyReference assemblyReference = new DefaultAssemblyReference(type.Assembly.FullName); + IModuleReference assemblyReference = new DefaultAssemblyReference(type.Assembly.FullName); int typeParameterCount; string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount); return new GetClassTypeReference(assemblyReference, type.Namespace, name, typeParameterCount); @@ -203,7 +203,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// For looking up closed, assembly qualified type names, the root type resolve context for the compilation /// is sufficient. /// When looking up a type name that isn't assembly qualified, the type reference will look in - /// first, and if the type is not found there, + /// first, and if the type is not found there, /// it will look in all other assemblies of the compilation. /// /// @@ -347,7 +347,7 @@ namespace ICSharpCode.Decompiler.TypeSystem static ITypeReference CreateGetClassTypeReference(string assemblyName, string typeName, int tpc) { - IAssemblyReference assemblyReference; + IModuleReference assemblyReference; if (assemblyName != null) { assemblyReference = new DefaultAssemblyReference(assemblyName); } else { diff --git a/ICSharpCode.Decompiler/TypeSystem/SimpleTypeResolveContext.cs b/ICSharpCode.Decompiler/TypeSystem/SimpleTypeResolveContext.cs index c3721cc1e..c9cf42375 100644 --- a/ICSharpCode.Decompiler/TypeSystem/SimpleTypeResolveContext.cs +++ b/ICSharpCode.Decompiler/TypeSystem/SimpleTypeResolveContext.cs @@ -26,7 +26,7 @@ namespace ICSharpCode.Decompiler.TypeSystem public class SimpleTypeResolveContext : ITypeResolveContext { readonly ICompilation compilation; - readonly IAssembly currentAssembly; + readonly IModule currentModule; readonly ITypeDefinition currentTypeDefinition; readonly IMember currentMember; @@ -37,12 +37,12 @@ namespace ICSharpCode.Decompiler.TypeSystem this.compilation = compilation; } - public SimpleTypeResolveContext(IAssembly assembly) + public SimpleTypeResolveContext(IModule module) { - if (assembly == null) - throw new ArgumentNullException("assembly"); - this.compilation = assembly.Compilation; - this.currentAssembly = assembly; + if (module == null) + throw new ArgumentNullException(nameof(module)); + this.compilation = module.Compilation; + this.currentModule = module; } public SimpleTypeResolveContext(IEntity entity) @@ -50,15 +50,15 @@ namespace ICSharpCode.Decompiler.TypeSystem if (entity == null) throw new ArgumentNullException("entity"); this.compilation = entity.Compilation; - this.currentAssembly = entity.ParentAssembly; + this.currentModule = entity.ParentModule; this.currentTypeDefinition = (entity as ITypeDefinition) ?? entity.DeclaringTypeDefinition; this.currentMember = entity as IMember; } - private SimpleTypeResolveContext(ICompilation compilation, IAssembly currentAssembly, ITypeDefinition currentTypeDefinition, IMember currentMember) + private SimpleTypeResolveContext(ICompilation compilation, IModule currentModule, ITypeDefinition currentTypeDefinition, IMember currentMember) { this.compilation = compilation; - this.currentAssembly = currentAssembly; + this.currentModule = currentModule; this.currentTypeDefinition = currentTypeDefinition; this.currentMember = currentMember; } @@ -67,8 +67,8 @@ namespace ICSharpCode.Decompiler.TypeSystem get { return compilation; } } - public IAssembly CurrentAssembly { - get { return currentAssembly; } + public IModule CurrentModule { + get { return currentModule; } } public ITypeDefinition CurrentTypeDefinition { @@ -81,12 +81,12 @@ namespace ICSharpCode.Decompiler.TypeSystem public ITypeResolveContext WithCurrentTypeDefinition(ITypeDefinition typeDefinition) { - return new SimpleTypeResolveContext(compilation, currentAssembly, typeDefinition, currentMember); + return new SimpleTypeResolveContext(compilation, currentModule, typeDefinition, currentMember); } public ITypeResolveContext WithCurrentMember(IMember member) { - return new SimpleTypeResolveContext(compilation, currentAssembly, currentTypeDefinition, member); + return new SimpleTypeResolveContext(compilation, currentModule, currentTypeDefinition, member); } } } diff --git a/ICSharpCode.Decompiler/TypeSystem/SpecializingDecompilerTypeSystem.cs b/ICSharpCode.Decompiler/TypeSystem/SpecializingDecompilerTypeSystem.cs index b5d78a80a..39068f56b 100644 --- a/ICSharpCode.Decompiler/TypeSystem/SpecializingDecompilerTypeSystem.cs +++ b/ICSharpCode.Decompiler/TypeSystem/SpecializingDecompilerTypeSystem.cs @@ -51,6 +51,7 @@ namespace ICSharpCode.Decompiler.TypeSystem } public Metadata.PEFile ModuleDefinition => context.ModuleDefinition; + public MetadataModule MainModule => context.MainModule; public TypeParameterSubstitution Substitution { get { return substitution; } @@ -97,11 +98,6 @@ namespace ICSharpCode.Decompiler.TypeSystem member = member.Specialize(substitution); return member; } - - public PEFile GetModuleDefinition(IAssembly assembly) - { - return context.GetModuleDefinition(assembly); - } MethodSignature IDecompilerTypeSystem.DecodeMethodSignature(StandaloneSignatureHandle standaloneSignatureHandle) { diff --git a/ICSharpCode.Decompiler/TypeSystem/TupleType.cs b/ICSharpCode.Decompiler/TypeSystem/TupleType.cs index 01d5ef12c..57582cde6 100644 --- a/ICSharpCode.Decompiler/TypeSystem/TupleType.cs +++ b/ICSharpCode.Decompiler/TypeSystem/TupleType.cs @@ -51,7 +51,7 @@ namespace ICSharpCode.Decompiler.TypeSystem public TupleType(ICompilation compilation, ImmutableArray elementTypes, ImmutableArray elementNames = default(ImmutableArray), - IAssembly valueTupleAssembly = null) + IModule valueTupleAssembly = null) { this.Compilation = compilation; this.UnderlyingType = CreateUnderlyingType(compilation, elementTypes, valueTupleAssembly); @@ -64,7 +64,7 @@ namespace ICSharpCode.Decompiler.TypeSystem } } - static ParameterizedType CreateUnderlyingType(ICompilation compilation, ImmutableArray elementTypes, IAssembly valueTupleAssembly) + static ParameterizedType CreateUnderlyingType(ICompilation compilation, ImmutableArray elementTypes, IModule valueTupleAssembly) { int remainder = (elementTypes.Length - 1) % (RestPosition - 1) + 1; Debug.Assert(remainder >= 1 && remainder < RestPosition); @@ -82,7 +82,7 @@ namespace ICSharpCode.Decompiler.TypeSystem return type; } - private static IType FindValueTupleType(ICompilation compilation, IAssembly valueTupleAssembly, int tpc) + private static IType FindValueTupleType(ICompilation compilation, IModule valueTupleAssembly, int tpc) { FullTypeName typeName = new TopLevelTypeName("System", "ValueTuple", tpc); if (valueTupleAssembly != null) { @@ -134,7 +134,7 @@ namespace ICSharpCode.Decompiler.TypeSystem return new TupleType( compilation, elementTypes, - valueTupleAssembly: type.GetDefinition()?.ParentAssembly + valueTupleAssembly: type.GetDefinition()?.ParentModule ); } else { return null; @@ -252,7 +252,7 @@ namespace ICSharpCode.Decompiler.TypeSystem } if (newElementTypes != null) { return new TupleType(this.Compilation, newElementTypes.ToImmutableArray(), this.ElementNames, - this.GetDefinition()?.ParentAssembly); + this.GetDefinition()?.ParentModule); } else { return this; } @@ -343,7 +343,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// public ImmutableArray ElementNames { get; } - public IAssemblyReference ValueTupleAssembly { get; } + public IModuleReference ValueTupleAssembly { get; } public TupleTypeReference(ImmutableArray elementTypes) { @@ -352,7 +352,7 @@ namespace ICSharpCode.Decompiler.TypeSystem public TupleTypeReference(ImmutableArray elementTypes, ImmutableArray elementNames = default(ImmutableArray), - IAssemblyReference valueTupleAssembly = null) + IModuleReference valueTupleAssembly = null) { this.ValueTupleAssembly = valueTupleAssembly; this.ElementTypes = elementTypes; diff --git a/ICSharpCode.Decompiler/TypeSystem/TypeProvider.cs b/ICSharpCode.Decompiler/TypeSystem/TypeProvider.cs index 17e990ca9..fbf241d41 100644 --- a/ICSharpCode.Decompiler/TypeSystem/TypeProvider.cs +++ b/ICSharpCode.Decompiler/TypeSystem/TypeProvider.cs @@ -32,13 +32,13 @@ namespace ICSharpCode.Decompiler.TypeSystem SRM.ISignatureTypeProvider, SRM.ICustomAttributeTypeProvider { - readonly MetadataAssembly assembly; + readonly MetadataModule module; readonly ICompilation compilation; - public TypeProvider(IAssembly assembly) + public TypeProvider(MetadataModule module) { - this.assembly = (MetadataAssembly)assembly; // TODO: change parameter type instead of casting - this.compilation = assembly.Compilation; + this.module = module; + this.compilation = module.Compilation; } public TypeProvider(ICompilation compilation) @@ -122,7 +122,7 @@ namespace ICSharpCode.Decompiler.TypeSystem public IType GetTypeFromDefinition(SRM.MetadataReader reader, SRM.TypeDefinitionHandle handle, byte rawTypeKind) { - ITypeDefinition td = assembly?.GetDefinition(handle); + ITypeDefinition td = module?.GetDefinition(handle); if (td != null) return td; bool? isReferenceType = IsReferenceType(reader, handle, rawTypeKind); @@ -131,10 +131,10 @@ namespace ICSharpCode.Decompiler.TypeSystem public IType GetTypeFromReference(SRM.MetadataReader reader, SRM.TypeReferenceHandle handle, byte rawTypeKind) { - var asmref = handle.GetDeclaringAssembly(reader); + var asmref = handle.GetDeclaringModule(reader); bool? isReferenceType = IsReferenceType(reader, handle, rawTypeKind); - var gctr = new GetClassTypeReference(handle.GetFullTypeName(reader), handle.GetDeclaringAssembly(reader), isReferenceType); - return gctr.Resolve(assembly != null ? new SimpleTypeResolveContext(assembly) : new SimpleTypeResolveContext(compilation)); + var gctr = new GetClassTypeReference(handle.GetFullTypeName(reader), handle.GetDeclaringModule(reader), isReferenceType); + return gctr.Resolve(module != null ? new SimpleTypeResolveContext(module) : new SimpleTypeResolveContext(compilation)); } public IType GetTypeFromSerializedName(string name) @@ -143,7 +143,7 @@ namespace ICSharpCode.Decompiler.TypeSystem return null; } return ReflectionHelper.ParseReflectionName(name) - .Resolve(assembly != null ? new SimpleTypeResolveContext(assembly) : new SimpleTypeResolveContext(compilation)); + .Resolve(module != null ? new SimpleTypeResolveContext(module) : new SimpleTypeResolveContext(compilation)); } public IType GetTypeFromSpecification(SRM.MetadataReader reader, GenericContext genericContext, SRM.TypeSpecificationHandle handle, byte rawTypeKind) diff --git a/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs b/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs index 529d3a38d..0e65c5fab 100644 --- a/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs +++ b/ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs @@ -262,7 +262,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// public static IEnumerable GetAllTypeDefinitions (this ICompilation compilation) { - return compilation.Assemblies.SelectMany(a => a.TypeDefinitions); + return compilation.Modules.SelectMany(a => a.TypeDefinitions); } /// @@ -271,7 +271,7 @@ namespace ICSharpCode.Decompiler.TypeSystem /// public static IEnumerable GetTopLevelTypeDefinitions (this ICompilation compilation) { - return compilation.Assemblies.SelectMany(a => a.TopLevelTypeDefinitions); + return compilation.Modules.SelectMany(a => a.TopLevelTypeDefinitions); } #endregion @@ -299,14 +299,14 @@ namespace ICSharpCode.Decompiler.TypeSystem /// There can be multiple types with the same full name in a compilation, as a /// full type name is only unique per assembly. /// If there are multiple possible matches, this method will return just one of them. - /// When possible, use instead to + /// When possible, use instead to /// retrieve a type from a specific assembly. /// public static IType FindType(this ICompilation compilation, FullTypeName fullTypeName) { if (compilation == null) throw new ArgumentNullException("compilation"); - foreach (IAssembly asm in compilation.Assemblies) { + foreach (IModule asm in compilation.Modules) { ITypeDefinition def = asm.GetTypeDefinition(fullTypeName); if (def != null) return def; @@ -318,12 +318,12 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the type definition for the specified unresolved type. /// Returns null if the unresolved type does not belong to this assembly. /// - public static ITypeDefinition GetTypeDefinition(this IAssembly assembly, FullTypeName fullTypeName) + public static ITypeDefinition GetTypeDefinition(this IModule module, FullTypeName fullTypeName) { - if (assembly == null) + if (module == null) throw new ArgumentNullException("assembly"); TopLevelTypeName topLevelTypeName = fullTypeName.TopLevelTypeName; - ITypeDefinition typeDef = assembly.GetTypeDefinition(topLevelTypeName); + ITypeDefinition typeDef = module.GetTypeDefinition(topLevelTypeName); if (typeDef == null) return null; int typeParameterCount = topLevelTypeName.TypeParameterCount; @@ -418,11 +418,11 @@ namespace ICSharpCode.Decompiler.TypeSystem /// Gets the type definition for a top-level type. /// /// This method uses ordinal name comparison, not the compilation's name comparer. - public static ITypeDefinition GetTypeDefinition(this IAssembly assembly, string namespaceName, string name, int typeParameterCount = 0) + public static ITypeDefinition GetTypeDefinition(this IModule module, string namespaceName, string name, int typeParameterCount = 0) { - if (assembly == null) + if (module == null) throw new ArgumentNullException ("assembly"); - return assembly.GetTypeDefinition (new TopLevelTypeName (namespaceName, name, typeParameterCount)); + return module.GetTypeDefinition (new TopLevelTypeName (namespaceName, name, typeParameterCount)); } #endregion diff --git a/ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs b/ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs index 96e3375d8..01cc6bc12 100644 --- a/ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs +++ b/ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs @@ -220,8 +220,8 @@ namespace ICSharpCode.Decompiler.TypeSystem get { return baseMethod.DeclaringType; } } - public IAssembly ParentAssembly { - get { return baseMethod.ParentAssembly; } + public IModule ParentModule { + get { return baseMethod.ParentModule; } } public bool IsStatic { diff --git a/ILSpy.BamlDecompiler/CecilType.cs b/ILSpy.BamlDecompiler/CecilType.cs index 30dc121ab..16a6ef3d0 100644 --- a/ILSpy.BamlDecompiler/CecilType.cs +++ b/ILSpy.BamlDecompiler/CecilType.cs @@ -22,7 +22,7 @@ namespace ILSpy.BamlDecompiler public string AssemblyQualifiedName { get { return type.FullName + - ", " + type.ParentAssembly.FullAssemblyName; + ", " + type.ParentModule.FullAssemblyName; } } diff --git a/ILSpy.BamlDecompiler/CecilTypeResolver.cs b/ILSpy.BamlDecompiler/CecilTypeResolver.cs index 877ec778d..19b04a3ab 100644 --- a/ILSpy.BamlDecompiler/CecilTypeResolver.cs +++ b/ILSpy.BamlDecompiler/CecilTypeResolver.cs @@ -27,7 +27,7 @@ namespace ILSpy.BamlDecompiler public bool IsLocalAssembly(string name) { - return MakeShort(name) == compilation.MainAssembly.AssemblyName; + return MakeShort(name) == compilation.MainModule.AssemblyName; } string MakeShort(string name) diff --git a/ILSpy/Analyzers/AnalyzerEntityTreeNode.cs b/ILSpy/Analyzers/AnalyzerEntityTreeNode.cs index 12e65a6ee..9fb696e53 100644 --- a/ILSpy/Analyzers/AnalyzerEntityTreeNode.cs +++ b/ILSpy/Analyzers/AnalyzerEntityTreeNode.cs @@ -40,7 +40,7 @@ namespace ICSharpCode.ILSpy.Analyzers public override bool HandleAssemblyListChanged(ICollection removedAssemblies, ICollection addedAssemblies) { foreach (LoadedAssembly asm in removedAssemblies) { - if (this.Member.ParentAssembly.PEFile == asm.GetPEFileOrNull()) + if (this.Member.ParentModule.PEFile == asm.GetPEFileOrNull()) return false; // remove this node } this.Children.RemoveAll( diff --git a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs index a4c17c8ed..2c3ab2d5e 100644 --- a/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs +++ b/ILSpy/Analyzers/AnalyzerSearchTreeNode.cs @@ -51,7 +51,7 @@ namespace ICSharpCode.ILSpy.Analyzers protected IEnumerable FetchChildren(CancellationToken ct) { if (analyzer is IEntityAnalyzer entityAnalyzer) { - var module = analyzedEntity.ParentAssembly.PEFile; + var module = analyzedEntity.ParentModule.PEFile; var ts = new DecompilerTypeSystem(module, module.GetAssemblyResolver()); var context = new AnalyzerContext(ts) { CancellationToken = ct, diff --git a/ILSpy/Analyzers/Builtin/EventImplementsInterfaceAnalyzer.cs b/ILSpy/Analyzers/Builtin/EventImplementsInterfaceAnalyzer.cs index 4386ecc2f..bdefe7cd1 100644 --- a/ILSpy/Analyzers/Builtin/EventImplementsInterfaceAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/EventImplementsInterfaceAnalyzer.cs @@ -34,14 +34,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin public IEnumerable Analyze(IEvent analyzedEntity, ITypeDefinition type, AnalyzerContext context) { var token = analyzedEntity.DeclaringTypeDefinition.MetadataToken; - var module = analyzedEntity.DeclaringTypeDefinition.ParentAssembly.PEFile; + var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.PEFile; if (!type.GetAllBaseTypeDefinitions() - .Any(t => t.MetadataToken == token && t.ParentAssembly.PEFile == module)) + .Any(t => t.MetadataToken == token && t.ParentModule.PEFile == module)) yield break; foreach (var @event in type.GetEvents(options: GetMemberOptions.ReturnMemberDefinitions)) { if (InheritanceHelper.GetBaseMembers(@event, true) - .Any(m => m.DeclaringTypeDefinition.MetadataToken == token && m.ParentAssembly.PEFile == module)) + .Any(m => m.DeclaringTypeDefinition.MetadataToken == token && m.ParentModule.PEFile == module)) yield return @event; } } diff --git a/ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs b/ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs index fa6eb5063..31e641463 100644 --- a/ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs @@ -34,14 +34,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin public IEnumerable Analyze(IEvent analyzedEntity, ITypeDefinition type, AnalyzerContext context) { if (!analyzedEntity.DeclaringType.GetAllBaseTypeDefinitions() - .Any(t => t.MetadataToken == analyzedEntity.DeclaringTypeDefinition.MetadataToken && t.ParentAssembly.PEFile == type.ParentAssembly.PEFile)) + .Any(t => t.MetadataToken == analyzedEntity.DeclaringTypeDefinition.MetadataToken && t.ParentModule.PEFile == type.ParentModule.PEFile)) yield break; foreach (var property in type.Properties) { if (!property.IsOverride) continue; if (InheritanceHelper.GetBaseMembers(property, false) .Any(p => p.MetadataToken == analyzedEntity.MetadataToken && - p.ParentAssembly.PEFile == analyzedEntity.ParentAssembly.PEFile)) { + p.ParentModule.PEFile == analyzedEntity.ParentModule.PEFile)) { yield return property; } } diff --git a/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs b/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs index c166dc4f0..9211d9a56 100644 --- a/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs @@ -89,7 +89,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin continue; found = field.MetadataToken == analyzedField.MetadataToken - && field.ParentAssembly.PEFile == analyzedField.ParentAssembly.PEFile; + && field.ParentModule.PEFile == analyzedField.ParentModule.PEFile; } if (found) { diff --git a/ILSpy/Analyzers/Builtin/MethodImplementsInterfaceAnalyzer.cs b/ILSpy/Analyzers/Builtin/MethodImplementsInterfaceAnalyzer.cs index 5345fb0fb..cf9109dde 100644 --- a/ILSpy/Analyzers/Builtin/MethodImplementsInterfaceAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/MethodImplementsInterfaceAnalyzer.cs @@ -37,14 +37,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin public IEnumerable Analyze(IMethod analyzedEntity, ITypeDefinition type, AnalyzerContext context) { var token = analyzedEntity.DeclaringTypeDefinition.MetadataToken; - var module = analyzedEntity.DeclaringTypeDefinition.ParentAssembly.PEFile; + var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.PEFile; if (!type.GetAllBaseTypeDefinitions() - .Any(t => t.MetadataToken == token && t.ParentAssembly.PEFile == module)) + .Any(t => t.MetadataToken == token && t.ParentModule.PEFile == module)) yield break; foreach (var method in type.GetMethods(options: GetMemberOptions.ReturnMemberDefinitions)) { if (InheritanceHelper.GetBaseMembers(method, true) - .Any(m => m.DeclaringTypeDefinition.MetadataToken == token && m.ParentAssembly.PEFile == module)) + .Any(m => m.DeclaringTypeDefinition.MetadataToken == token && m.ParentModule.PEFile == module)) yield return method; } } diff --git a/ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs b/ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs index cae118c4d..13324484f 100644 --- a/ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs @@ -34,14 +34,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin public IEnumerable Analyze(IMethod analyzedEntity, ITypeDefinition type, AnalyzerContext context) { if (!analyzedEntity.DeclaringType.GetAllBaseTypeDefinitions() - .Any(t => t.MetadataToken == analyzedEntity.DeclaringTypeDefinition.MetadataToken && t.ParentAssembly.PEFile == type.ParentAssembly.PEFile)) + .Any(t => t.MetadataToken == analyzedEntity.DeclaringTypeDefinition.MetadataToken && t.ParentModule.PEFile == type.ParentModule.PEFile)) yield break; foreach (var property in type.Properties) { if (!property.IsOverride) continue; if (InheritanceHelper.GetBaseMembers(property, false) .Any(p => p.MetadataToken == analyzedEntity.MetadataToken && - p.ParentAssembly.PEFile == analyzedEntity.ParentAssembly.PEFile)) { + p.ParentModule.PEFile == analyzedEntity.ParentModule.PEFile)) { yield return property; } } diff --git a/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs b/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs index d8d8706ce..c0a6ebdd5 100644 --- a/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs @@ -74,7 +74,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin static bool IsSameMember(IMember analyzedMethod, IMember m) { return m.MetadataToken == analyzedMethod.MetadataToken - && m.ParentAssembly.PEFile == analyzedMethod.ParentAssembly.PEFile; + && m.ParentModule.PEFile == analyzedMethod.ParentModule.PEFile; } } } diff --git a/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs b/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs index bd3fc8bb6..3fd348f24 100644 --- a/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs @@ -48,7 +48,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin IEnumerable ScanMethod(IMethod analyzedMethod, MethodDefinitionHandle handle, AnalyzerContext context) { - var module = analyzedMethod.ParentAssembly.PEFile; + var module = analyzedMethod.ParentModule.PEFile; var md = module.Metadata.GetMethodDefinition(handle); if (!md.HasBody()) yield break; diff --git a/ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs b/ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs index 474e1fdf1..626b996db 100644 --- a/ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs @@ -56,7 +56,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin case HandleKind.MethodSpecification: case HandleKind.MemberReference: var m = context.TypeSystem.ResolveAsMember(member)?.MemberDefinition; - if (m.MetadataToken == analyzedMethod.MetadataToken && m.ParentAssembly.PEFile == analyzedMethod.ParentAssembly.PEFile) { + if (m.MetadataToken == analyzedMethod.MetadataToken && m.ParentModule.PEFile == analyzedMethod.ParentModule.PEFile) { yield return method; yield break; } diff --git a/ILSpy/Analyzers/Builtin/PropertyImplementsInterfaceAnalyzer.cs b/ILSpy/Analyzers/Builtin/PropertyImplementsInterfaceAnalyzer.cs index 06c6f8381..8b6b5c10d 100644 --- a/ILSpy/Analyzers/Builtin/PropertyImplementsInterfaceAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/PropertyImplementsInterfaceAnalyzer.cs @@ -34,14 +34,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin public IEnumerable Analyze(IProperty analyzedEntity, ITypeDefinition type, AnalyzerContext context) { var token = analyzedEntity.DeclaringTypeDefinition.MetadataToken; - var module = analyzedEntity.DeclaringTypeDefinition.ParentAssembly.PEFile; + var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.PEFile; if (!type.GetAllBaseTypeDefinitions() - .Any(t => t.MetadataToken == token && t.ParentAssembly.PEFile == module)) + .Any(t => t.MetadataToken == token && t.ParentModule.PEFile == module)) yield break; foreach (var property in type.GetProperties(options: GetMemberOptions.ReturnMemberDefinitions)) { if (InheritanceHelper.GetBaseMembers(property, true) - .Any(m => m.DeclaringTypeDefinition.MetadataToken == token && m.ParentAssembly.PEFile == module)) + .Any(m => m.DeclaringTypeDefinition.MetadataToken == token && m.ParentModule.PEFile == module)) yield return property; } } diff --git a/ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs b/ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs index ff7fa52ec..9abd743e3 100644 --- a/ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs @@ -37,14 +37,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin public IEnumerable Analyze(IProperty analyzedEntity, ITypeDefinition type, AnalyzerContext context) { if (!analyzedEntity.DeclaringType.GetAllBaseTypeDefinitions() - .Any(t => t.MetadataToken == analyzedEntity.DeclaringTypeDefinition.MetadataToken && t.ParentAssembly.PEFile == type.ParentAssembly.PEFile)) + .Any(t => t.MetadataToken == analyzedEntity.DeclaringTypeDefinition.MetadataToken && t.ParentModule.PEFile == type.ParentModule.PEFile)) yield break; foreach (var property in type.Properties) { if (!property.IsOverride) continue; if (InheritanceHelper.GetBaseMembers(property, false) .Any(p => p.MetadataToken == analyzedEntity.MetadataToken && - p.ParentAssembly.PEFile == analyzedEntity.ParentAssembly.PEFile)) { + p.ParentModule.PEFile == analyzedEntity.ParentModule.PEFile)) { yield return property; } } diff --git a/ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs b/ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs index 97db4f9f3..e2e8210f8 100644 --- a/ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs @@ -40,7 +40,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin { if (analyzedType.Kind == TypeKind.Enum && type.MetadataToken == analyzedType.MetadataToken - && type.ParentAssembly.PEFile == analyzedType.ParentAssembly.PEFile) + && type.ParentModule.PEFile == analyzedType.ParentModule.PEFile) yield break; if (!context.Language.ShowMember(type)) diff --git a/ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs b/ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs index d5f5bd40c..7f62b1d2b 100644 --- a/ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs @@ -57,7 +57,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin continue; found = ctor.DeclaringTypeDefinition?.MetadataToken == analyzedEntity.MetadataToken - && ctor.ParentAssembly.PEFile == analyzedEntity.ParentAssembly.PEFile; + && ctor.ParentModule.PEFile == analyzedEntity.ParentModule.PEFile; } if (found) { diff --git a/ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs b/ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs index 93434ff4d..c0737aa90 100644 --- a/ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs +++ b/ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs @@ -141,7 +141,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin public IEnumerable Analyze(ITypeDefinition analyzedEntity, ITypeDefinition type, AnalyzerContext context) { - if (analyzedEntity.ParentAssembly.PEFile == type.ParentAssembly.PEFile + if (analyzedEntity.ParentModule.PEFile == type.ParentModule.PEFile && analyzedEntity.MetadataToken == type.MetadataToken) yield break; @@ -185,7 +185,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin public override IType VisitTypeDefinition(ITypeDefinition type) { Found |= typeDefinition.MetadataToken == type.MetadataToken - && typeDefinition.ParentAssembly.PEFile == type.ParentAssembly.PEFile; + && typeDefinition.ParentModule.PEFile == type.ParentModule.PEFile; return base.VisitTypeDefinition(type); } } diff --git a/ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs b/ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs index 7334171d2..b7f858d5e 100644 --- a/ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs +++ b/ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs @@ -35,7 +35,7 @@ namespace ICSharpCode.ILSpy.Analyzers { readonly Language language; readonly IAnalyzer analyzer; - readonly IAssembly assemblyScope; + readonly IModule assemblyScope; readonly T analyzedEntity; ITypeDefinition typeScope; @@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy.Analyzers this.language = language ?? throw new ArgumentNullException(nameof(language)); this.analyzer = analyzer ?? throw new ArgumentNullException(nameof(analyzer)); this.analyzedEntity = analyzedEntity; - this.assemblyScope = analyzedEntity.ParentAssembly; + this.assemblyScope = analyzedEntity.ParentModule; if (analyzedEntity is ITypeDefinition type) { this.typeScope = type; this.typeAccessibility = type.Accessibility; @@ -112,7 +112,7 @@ namespace ICSharpCode.ILSpy.Analyzers { var ts = new DecompilerTypeSystem(module, module.GetAssemblyResolver()); var context = new AnalyzerContext(ts) { CancellationToken = ct, Language = language }; - foreach (var type in ts.MainAssembly.TypeDefinitions) { + foreach (var type in ts.MainModule.TypeDefinitions) { ct.ThrowIfCancellationRequested(); if (type.MetadataToken.IsNil) continue; context.CodeMappingInfo = language.GetCodeMappingInfo(module, type.MetadataToken); diff --git a/ILSpy/Languages/CSharpLanguage.cs b/ILSpy/Languages/CSharpLanguage.cs index cbda0f8b5..2d831364c 100644 --- a/ILSpy/Languages/CSharpLanguage.cs +++ b/ILSpy/Languages/CSharpLanguage.cs @@ -131,7 +131,7 @@ namespace ICSharpCode.ILSpy public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { - PEFile assembly = method.ParentAssembly.PEFile; + PEFile assembly = method.ParentModule.PEFile; AddReferenceWarningMessage(assembly, output); WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true)); CSharpDecompiler decompiler = CreateDecompiler(assembly, options); @@ -198,7 +198,7 @@ namespace ICSharpCode.ILSpy public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options) { - PEFile assembly = property.ParentAssembly.PEFile; + PEFile assembly = property.ParentModule.PEFile; AddReferenceWarningMessage(assembly, output); CSharpDecompiler decompiler = CreateDecompiler(assembly, options); WriteCommentLine(output, TypeToString(property.DeclaringType, includeNamespace: true)); @@ -207,7 +207,7 @@ namespace ICSharpCode.ILSpy public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options) { - PEFile assembly = field.ParentAssembly.PEFile; + PEFile assembly = field.ParentModule.PEFile; AddReferenceWarningMessage(assembly, output); WriteCommentLine(output, TypeToString(field.DeclaringType, includeNamespace: true)); CSharpDecompiler decompiler = CreateDecompiler(assembly, options); @@ -266,7 +266,7 @@ namespace ICSharpCode.ILSpy public override void DecompileEvent(IEvent @event, ITextOutput output, DecompilationOptions options) { - PEFile assembly = @event.ParentAssembly.PEFile; + PEFile assembly = @event.ParentModule.PEFile; AddReferenceWarningMessage(assembly, output); base.WriteCommentLine(output, TypeToString(@event.DeclaringType, includeNamespace: true)); CSharpDecompiler decompiler = CreateDecompiler(assembly, options); @@ -275,7 +275,7 @@ namespace ICSharpCode.ILSpy public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options) { - PEFile assembly = type.ParentAssembly.PEFile; + PEFile assembly = type.ParentModule.PEFile; AddReferenceWarningMessage(assembly, output); WriteCommentLine(output, TypeToString(type, includeNamespace: true)); CSharpDecompiler decompiler = CreateDecompiler(assembly, options); @@ -331,7 +331,7 @@ namespace ICSharpCode.ILSpy using (options.FullDecompilation ? null : LoadedAssembly.DisableAssemblyLoad()) { IAssemblyResolver assemblyResolver = assembly.GetAssemblyResolver(); var typeSystem = new DecompilerTypeSystem(module, assemblyResolver, options.DecompilerSettings); - var globalType = typeSystem.MainAssembly.TypeDefinitions.FirstOrDefault(); + var globalType = typeSystem.MainModule.TypeDefinitions.FirstOrDefault(); if (globalType != null) { output.Write("// Global type: "); output.WriteReference(globalType, globalType.FullName); @@ -556,7 +556,7 @@ namespace ICSharpCode.ILSpy public override bool ShowMember(IEntity member) { - PEFile assembly = member.ParentAssembly.PEFile; + PEFile assembly = member.ParentModule.PEFile; return showAllMembers || !CSharpDecompiler.MemberIsHidden(assembly, member.MetadataToken, new DecompilationOptions().DecompilerSettings); } diff --git a/ILSpy/Languages/ILAstLanguage.cs b/ILSpy/Languages/ILAstLanguage.cs index a7c0e1509..9b00afcd2 100644 --- a/ILSpy/Languages/ILAstLanguage.cs +++ b/ILSpy/Languages/ILAstLanguage.cs @@ -74,7 +74,7 @@ namespace ICSharpCode.ILSpy { base.DecompileMethod(method, output, options); new ReflectionDisassembler(output, options.CancellationToken) - .DisassembleMethodHeader(method.ParentAssembly.PEFile, (SRM.MethodDefinitionHandle)method.MetadataToken); + .DisassembleMethodHeader(method.ParentModule.PEFile, (SRM.MethodDefinitionHandle)method.MetadataToken); output.WriteLine(); output.WriteLine(); } @@ -86,7 +86,7 @@ namespace ICSharpCode.ILSpy public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { base.DecompileMethod(method, output, options); - var module = method.ParentAssembly.PEFile; + var module = method.ParentModule.PEFile; var methodDef = module.Metadata.GetMethodDefinition((SRM.MethodDefinitionHandle)method.MetadataToken); if (!methodDef.HasBody()) return; @@ -109,7 +109,7 @@ namespace ICSharpCode.ILSpy public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { base.DecompileMethod(method, output, options); - var module = method.ParentAssembly.PEFile; + var module = method.ParentModule.PEFile; var metadata = module.Metadata; var methodDef = metadata.GetMethodDefinition((SRM.MethodDefinitionHandle)method.MetadataToken); if (!methodDef.HasBody()) diff --git a/ILSpy/Languages/ILLanguage.cs b/ILSpy/Languages/ILLanguage.cs index 9ccd86bfe..243a8bcda 100644 --- a/ILSpy/Languages/ILLanguage.cs +++ b/ILSpy/Languages/ILLanguage.cs @@ -63,21 +63,21 @@ namespace ICSharpCode.ILSpy public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - dis.AssemblyResolver = method.ParentAssembly.PEFile.GetAssemblyResolver(); - dis.DisassembleMethod(method.ParentAssembly.PEFile, (MethodDefinitionHandle)method.MetadataToken); + dis.AssemblyResolver = method.ParentModule.PEFile.GetAssemblyResolver(); + dis.DisassembleMethod(method.ParentModule.PEFile, (MethodDefinitionHandle)method.MetadataToken); } public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - dis.AssemblyResolver = field.ParentAssembly.PEFile.GetAssemblyResolver(); - dis.DisassembleField(field.ParentAssembly.PEFile, (FieldDefinitionHandle)field.MetadataToken); + dis.AssemblyResolver = field.ParentModule.PEFile.GetAssemblyResolver(); + dis.DisassembleField(field.ParentModule.PEFile, (FieldDefinitionHandle)field.MetadataToken); } public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - PEFile module = property.ParentAssembly.PEFile; + PEFile module = property.ParentModule.PEFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DisassembleProperty(module, (PropertyDefinitionHandle)property.MetadataToken); var pd = module.Metadata.GetPropertyDefinition((PropertyDefinitionHandle)property.MetadataToken); @@ -100,7 +100,7 @@ namespace ICSharpCode.ILSpy public override void DecompileEvent(IEvent ev, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - PEFile module = ev.ParentAssembly.PEFile; + PEFile module = ev.ParentModule.PEFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DisassembleEvent(module, (EventDefinitionHandle)ev.MetadataToken); @@ -127,7 +127,7 @@ namespace ICSharpCode.ILSpy public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - PEFile module = type.ParentAssembly.PEFile; + PEFile module = type.ParentModule.PEFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DisassembleType(module, (TypeDefinitionHandle)type.MetadataToken); } @@ -135,7 +135,7 @@ namespace ICSharpCode.ILSpy public override void DecompileNamespace(string nameSpace, IEnumerable types, ITextOutput output, DecompilationOptions options) { var dis = CreateDisassembler(output, options); - PEFile module = types.FirstOrDefault()?.ParentAssembly.PEFile; + PEFile module = types.FirstOrDefault()?.ParentModule.PEFile; dis.AssemblyResolver = module.GetAssemblyResolver(); dis.DisassembleNamespace(nameSpace, module, types.Select(t => (TypeDefinitionHandle)t.MetadataToken)); } diff --git a/ILSpy/SearchPane.cs b/ILSpy/SearchPane.cs index 74a486953..13feda9a4 100644 --- a/ILSpy/SearchPane.cs +++ b/ILSpy/SearchPane.cs @@ -222,7 +222,7 @@ namespace ICSharpCode.ILSpy continue; CancellationToken cancellationToken = cts.Token; - foreach (var type in typeSystem.MainAssembly.TopLevelTypeDefinitions) { + foreach (var type in typeSystem.MainModule.TopLevelTypeDefinitions) { cancellationToken.ThrowIfCancellationRequested(); searcher.Search(type, language, AddResult); } diff --git a/ILSpy/SearchStrategies.cs b/ILSpy/SearchStrategies.cs index 0b1ea3f0c..d868ddfdb 100644 --- a/ILSpy/SearchStrategies.cs +++ b/ILSpy/SearchStrategies.cs @@ -321,7 +321,7 @@ namespace ICSharpCode.ILSpy { if (method == null) return false; - var module = ((MetadataAssembly)method.ParentAssembly).PEFile; + var module = ((MetadataModule)method.ParentModule).PEFile; var m = (SRM.MethodDefinitionHandle)method.MetadataToken; if (m.IsNil) return false; diff --git a/ILSpy/TextView/DecompilerTextView.cs b/ILSpy/TextView/DecompilerTextView.cs index b82b94363..70f032501 100644 --- a/ILSpy/TextView/DecompilerTextView.cs +++ b/ILSpy/TextView/DecompilerTextView.cs @@ -211,9 +211,9 @@ namespace ICSharpCode.ILSpy.TextView XmlDocRenderer renderer = new XmlDocRenderer(); renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(entity)); try { - if (entity.ParentAssembly == null || entity.ParentAssembly.PEFile == null) + if (entity.ParentModule == null || entity.ParentModule.PEFile == null) return null; - var docProvider = XmlDocLoader.LoadDocumentation(entity.ParentAssembly.PEFile); + var docProvider = XmlDocLoader.LoadDocumentation(entity.ParentModule.PEFile); if (docProvider != null) { string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(entity)); if (documentation != null) { @@ -237,9 +237,9 @@ namespace ICSharpCode.ILSpy.TextView XmlDocRenderer renderer = new XmlDocRenderer(); renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(resolved)); try { - if (resolved.ParentAssembly == null || resolved.ParentAssembly.PEFile == null) + if (resolved.ParentModule == null || resolved.ParentModule.PEFile == null) return null; - var docProvider = XmlDocLoader.LoadDocumentation(resolved.ParentAssembly.PEFile); + var docProvider = XmlDocLoader.LoadDocumentation(resolved.ParentModule.PEFile); if (docProvider != null) { string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(resolved)); if (documentation != null) { diff --git a/ILSpy/TreeNodes/AssemblyListTreeNode.cs b/ILSpy/TreeNodes/AssemblyListTreeNode.cs index 99ec2312d..569eef00a 100644 --- a/ILSpy/TreeNodes/AssemblyListTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyListTreeNode.cs @@ -177,11 +177,9 @@ namespace ICSharpCode.ILSpy.TreeNodes return null; } - public AssemblyTreeNode FindAssemblyNode(IAssembly module) + public AssemblyTreeNode FindAssemblyNode(IModule module) { - if (!(module is MetadataAssembly assembly)) - return null; - return FindAssemblyNode(assembly.PEFile); + return FindAssemblyNode(module.PEFile); } public AssemblyTreeNode FindAssemblyNode(PEFile module) @@ -224,7 +222,7 @@ namespace ICSharpCode.ILSpy.TreeNodes return decl.Children.OfType().FirstOrDefault(t => t.TypeDefinition.MetadataToken == def.MetadataToken && !t.IsHidden); } } else { - AssemblyTreeNode asm = FindAssemblyNode(def.ParentAssembly); + AssemblyTreeNode asm = FindAssemblyNode(def.ParentModule); if (asm != null) { return asm.FindTypeNode(def); } diff --git a/ILSpy/TreeNodes/AssemblyTreeNode.cs b/ILSpy/TreeNodes/AssemblyTreeNode.cs index a4d433e19..c7f0937a1 100644 --- a/ILSpy/TreeNodes/AssemblyTreeNode.cs +++ b/ILSpy/TreeNodes/AssemblyTreeNode.cs @@ -140,7 +140,7 @@ namespace ICSharpCode.ILSpy.TreeNodes return; } typeSystem = LoadedAssembly.GetTypeSystemOrNull(); - var assembly = (MetadataAssembly)typeSystem.MainAssembly; + var assembly = (MetadataModule)typeSystem.MainModule; var metadata = module.Metadata; this.Children.Add(new ReferenceFolderTreeNode(module, this)); diff --git a/ILSpy/TreeNodes/BaseTypesEntryNode.cs b/ILSpy/TreeNodes/BaseTypesEntryNode.cs index 5751e0177..183d90999 100644 --- a/ILSpy/TreeNodes/BaseTypesEntryNode.cs +++ b/ILSpy/TreeNodes/BaseTypesEntryNode.cs @@ -53,7 +53,7 @@ namespace ICSharpCode.ILSpy.TreeNodes var t = typeSystem.ResolveAsType(handle).GetDefinition(); if (t != null) { showExpander = t.DirectBaseTypes.Any(); - var other = t.ParentAssembly.PEFile.GetTypeSystemOrNull(); + var other = t.ParentModule.PEFile.GetTypeSystemOrNull(); Debug.Assert(other != null); t = other.FindType(t.FullTypeName).GetDefinition(); } else { @@ -74,7 +74,7 @@ namespace ICSharpCode.ILSpy.TreeNodes { var t = TryResolve(module, handle, type, false); if (t != null) { - BaseTypesTreeNode.AddBaseTypes(this.Children, t.ParentAssembly.PEFile, t); + BaseTypesTreeNode.AddBaseTypes(this.Children, t.ParentModule.PEFile, t); } } diff --git a/ILSpy/TreeNodes/DerivedTypesTreeNode.cs b/ILSpy/TreeNodes/DerivedTypesTreeNode.cs index 19b9c1827..456805362 100644 --- a/ILSpy/TreeNodes/DerivedTypesTreeNode.cs +++ b/ILSpy/TreeNodes/DerivedTypesTreeNode.cs @@ -63,11 +63,11 @@ namespace ICSharpCode.ILSpy.TreeNodes internal static IEnumerable FindDerivedTypes(AssemblyList list, ITypeDefinition type, PEFile[] assemblies, CancellationToken cancellationToken) { - var definitionMetadata = type.ParentAssembly.PEFile.Metadata; + var definitionMetadata = type.ParentModule.PEFile.Metadata; var metadataToken = (SRM.TypeDefinitionHandle)type.MetadataToken; foreach (var module in assemblies) { var metadata = module.Metadata; - var assembly = (MetadataAssembly)module.GetTypeSystemOrNull().MainAssembly; + var assembly = (MetadataModule)module.GetTypeSystemOrNull().MainModule; foreach (var h in metadata.TypeDefinitions) { cancellationToken.ThrowIfCancellationRequested(); var td = metadata.GetTypeDefinition(h); diff --git a/ILSpy/TypeExtensionMethodsAnalyzer.cs b/ILSpy/TypeExtensionMethodsAnalyzer.cs index 6e8fa10e4..5150e0c2e 100644 --- a/ILSpy/TypeExtensionMethodsAnalyzer.cs +++ b/ILSpy/TypeExtensionMethodsAnalyzer.cs @@ -25,7 +25,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin var firstParamType = method.Parameters[0].Type.GetDefinition(); if (firstParamType != null && firstParamType.MetadataToken == analyzedType.MetadataToken && - firstParamType.ParentAssembly.PEFile == analyzedType.ParentAssembly.PEFile) + firstParamType.ParentModule.PEFile == analyzedType.ParentModule.PEFile) yield return method; } } diff --git a/TestPlugin/CustomLanguage.cs b/TestPlugin/CustomLanguage.cs index 17b60319c..b0405cbf9 100644 --- a/TestPlugin/CustomLanguage.cs +++ b/TestPlugin/CustomLanguage.cs @@ -33,7 +33,7 @@ namespace TestPlugin // There are several methods available to override; in this sample, we deal with methods only public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) { - var module = ((MetadataAssembly)method.ParentAssembly).PEFile; + var module = ((MetadataModule)method.ParentModule).PEFile; var methodDef = module.Metadata.GetMethodDefinition((MethodDefinitionHandle)method.MetadataToken); if (methodDef.HasBody()) { var methodBody = module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);