Browse Source

Rename IAssembly -> IModule.

While support for multi-module assemblies isn't fully working yet; it is clear at this point that we want
to treat each module in a multi-module assembly separately for the purposes of the type system.
pull/1030/head
Daniel Grunwald 7 years ago
parent
commit
3b46776c5e
  1. 2
      ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs
  2. 6
      ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs
  3. 16
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  4. 6
      ICSharpCode.Decompiler/CSharp/CallBuilder.cs
  5. 4
      ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs
  6. 10
      ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs
  7. 4
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpOperators.cs
  8. 12
      ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs
  9. 16
      ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs
  10. 4
      ICSharpCode.Decompiler/CSharp/Resolver/ReducedExtensionMethod.cs
  11. 2
      ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs
  12. 4
      ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs
  13. 6
      ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs
  14. 6
      ICSharpCode.Decompiler/CSharp/Transforms/TransformContext.cs
  15. 26
      ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs
  16. 4
      ICSharpCode.Decompiler/CSharp/TypeSystem/ResolvedUsingScope.cs
  17. 2
      ICSharpCode.Decompiler/CSharp/TypeSystem/TypeOrNamespaceReference.cs
  18. 2
      ICSharpCode.Decompiler/CSharp/TypeSystem/UsingScope.cs
  19. 6
      ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs
  20. 2
      ICSharpCode.Decompiler/Documentation/GetPotentiallyNestedClassTypeReference.cs
  21. 11
      ICSharpCode.Decompiler/Documentation/IdStringProvider.cs
  22. 4
      ICSharpCode.Decompiler/Documentation/XmlDocKeyProvider.cs
  23. 4
      ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj
  24. 2
      ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs
  25. 2
      ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs
  26. 4
      ICSharpCode.Decompiler/Metadata/MetadataExtensions.cs
  27. 27
      ICSharpCode.Decompiler/Metadata/PEFile.cs
  28. 4
      ICSharpCode.Decompiler/SRMExtensions.cs
  29. 2
      ICSharpCode.Decompiler/TypeSystem/ApplyAttributeTypeVisitor.cs
  30. 2
      ICSharpCode.Decompiler/TypeSystem/AssemblyQualifiedTypeName.cs
  31. 32
      ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs
  32. 32
      ICSharpCode.Decompiler/TypeSystem/IAssembly.cs
  33. 18
      ICSharpCode.Decompiler/TypeSystem/ICompilation.cs
  34. 2
      ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs
  35. 5
      ICSharpCode.Decompiler/TypeSystem/IEntity.cs
  36. 4
      ICSharpCode.Decompiler/TypeSystem/INamespace.cs
  37. 6
      ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs
  38. 56
      ICSharpCode.Decompiler/TypeSystem/Implementation/AttributeListBuilder.cs
  39. 12
      ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs
  40. 16
      ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultAssemblyReference.cs
  41. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs
  42. 32
      ICSharpCode.Decompiler/TypeSystem/Implementation/GetClassTypeReference.cs
  43. 2
      ICSharpCode.Decompiler/TypeSystem/Implementation/KnownTypeCache.cs
  44. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/MergedNamespace.cs
  45. 34
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs
  46. 40
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs
  47. 68
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs
  48. 24
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataNamespace.cs
  49. 18
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs
  50. 41
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataProperty.cs
  51. 80
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs
  52. 32
      ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeParameter.cs
  53. 30
      ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs
  54. 67
      ICSharpCode.Decompiler/TypeSystem/Implementation/PinnedType.cs
  55. 36
      ICSharpCode.Decompiler/TypeSystem/Implementation/SimpleCompilation.cs
  56. 4
      ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMember.cs
  57. 29
      ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs
  58. 6
      ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs
  59. 26
      ICSharpCode.Decompiler/TypeSystem/SimpleTypeResolveContext.cs
  60. 6
      ICSharpCode.Decompiler/TypeSystem/SpecializingDecompilerTypeSystem.cs
  61. 14
      ICSharpCode.Decompiler/TypeSystem/TupleType.cs
  62. 18
      ICSharpCode.Decompiler/TypeSystem/TypeProvider.cs
  63. 20
      ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs
  64. 4
      ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs
  65. 2
      ILSpy.BamlDecompiler/CecilType.cs
  66. 2
      ILSpy.BamlDecompiler/CecilTypeResolver.cs
  67. 2
      ILSpy/Analyzers/AnalyzerEntityTreeNode.cs
  68. 2
      ILSpy/Analyzers/AnalyzerSearchTreeNode.cs
  69. 6
      ILSpy/Analyzers/Builtin/EventImplementsInterfaceAnalyzer.cs
  70. 4
      ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs
  71. 2
      ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs
  72. 6
      ILSpy/Analyzers/Builtin/MethodImplementsInterfaceAnalyzer.cs
  73. 4
      ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs
  74. 2
      ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs
  75. 2
      ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs
  76. 2
      ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs
  77. 6
      ILSpy/Analyzers/Builtin/PropertyImplementsInterfaceAnalyzer.cs
  78. 4
      ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs
  79. 2
      ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs
  80. 2
      ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs
  81. 4
      ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs
  82. 6
      ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs
  83. 14
      ILSpy/Languages/CSharpLanguage.cs
  84. 6
      ILSpy/Languages/ILAstLanguage.cs
  85. 16
      ILSpy/Languages/ILLanguage.cs
  86. 2
      ILSpy/SearchPane.cs
  87. 2
      ILSpy/SearchStrategies.cs
  88. 8
      ILSpy/TextView/DecompilerTextView.cs
  89. 8
      ILSpy/TreeNodes/AssemblyListTreeNode.cs
  90. 2
      ILSpy/TreeNodes/AssemblyTreeNode.cs
  91. 4
      ILSpy/TreeNodes/BaseTypesEntryNode.cs
  92. 4
      ILSpy/TreeNodes/DerivedTypesTreeNode.cs
  93. 2
      ILSpy/TypeExtensionMethodsAnalyzer.cs
  94. 2
      TestPlugin/CustomLanguage.cs

2
ICSharpCode.Decompiler.Tests/Semantics/OverloadResolutionTests.cs

@ -49,7 +49,7 @@ namespace ICSharpCode.Decompiler.Tests.Semantics
IMethod MakeMethod(params object[] parameterTypesOrDefaultValues) IMethod MakeMethod(params object[] parameterTypesOrDefaultValues)
{ {
var context = new SimpleTypeResolveContext(compilation.MainAssembly); var context = new SimpleTypeResolveContext(compilation.MainModule);
var m = new FakeMethod(compilation, SymbolKind.Method); var m = new FakeMethod(compilation, SymbolKind.Method);
m.Name = "Method"; m.Name = "Method";
var parameters = new List<IParameter>(); var parameters = new List<IParameter>();

6
ICSharpCode.Decompiler.Tests/TypeSystem/TypeSystemLoaderTests.cs

@ -159,7 +159,7 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem
[Test] [Test]
public void AssemblyAttribute() 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); var typeTest = attributes.Single(a => a.AttributeType.FullName == typeof(TypeTestAttribute).FullName);
Assert.AreEqual(3, typeTest.FixedArguments.Length); Assert.AreEqual(3, typeTest.FixedArguments.Length);
// first argument is (int)42 // first argument is (int)42
@ -185,7 +185,7 @@ namespace ICSharpCode.Decompiler.Tests.TypeSystem
[Test] [Test]
public void TypeForwardedTo_Attribute() 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); var forwardAttribute = attributes.Single(a => a.AttributeType.FullName == typeof(TypeForwardedToAttribute).FullName);
Assert.AreEqual(1, forwardAttribute.FixedArguments.Length); Assert.AreEqual(1, forwardAttribute.FixedArguments.Length);
var rt = (IType)forwardAttribute.FixedArguments[0].Value; 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"); var typeRef = ReflectionHelper.ParseReflectionName("System.Func`2, System.Core");
ITypeDefinition c = typeRef.Resolve(compilationWithSystemCore.TypeResolveContext).GetDefinition(); ITypeDefinition c = typeRef.Resolve(compilationWithSystemCore.TypeResolveContext).GetDefinition();
Assert.IsNotNull(c, "System.Func<,> not found"); Assert.IsNotNull(c, "System.Func<,> not found");
Assert.AreEqual("mscorlib", c.ParentAssembly.AssemblyName); Assert.AreEqual("mscorlib", c.ParentModule.AssemblyName);
} }
public void DelegateIsClass() public void DelegateIsClass()

16
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -374,7 +374,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// </summary> /// </summary>
public SyntaxTree DecompileModuleAndAssemblyAttributes() public SyntaxTree DecompileModuleAndAssemblyAttributes()
{ {
var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainAssembly); var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainModule);
var decompileRun = new DecompileRun(settings) { var decompileRun = new DecompileRun(settings) {
DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(), DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(),
CancellationToken = CancellationToken CancellationToken = CancellationToken
@ -396,13 +396,13 @@ namespace ICSharpCode.Decompiler.CSharp
void DoDecompileModuleAndAssemblyAttributes(DecompileRun decompileRun, ITypeResolveContext decompilationContext, SyntaxTree syntaxTree) 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 astBuilder = CreateAstBuilder(decompilationContext);
var attrSection = new AttributeSection(astBuilder.ConvertAttribute(a)); var attrSection = new AttributeSection(astBuilder.ConvertAttribute(a));
attrSection.AttributeTarget = "assembly"; attrSection.AttributeTarget = "assembly";
syntaxTree.AddChild(attrSection, SyntaxTree.MemberRole); 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 astBuilder = CreateAstBuilder(decompilationContext);
var attrSection = new AttributeSection(astBuilder.ConvertAttribute(a)); var attrSection = new AttributeSection(astBuilder.ConvertAttribute(a));
attrSection.AttributeTarget = "module"; attrSection.AttributeTarget = "module";
@ -439,7 +439,7 @@ namespace ICSharpCode.Decompiler.CSharp
/// </summary> /// </summary>
public SyntaxTree DecompileWholeModuleAsSingleFile() public SyntaxTree DecompileWholeModuleAsSingleFile()
{ {
var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainAssembly); var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainModule);
var decompileRun = new DecompileRun(settings) { var decompileRun = new DecompileRun(settings) {
DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(), DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(),
CancellationToken = CancellationToken CancellationToken = CancellationToken
@ -566,7 +566,7 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
if (types == null) if (types == null)
throw new ArgumentNullException(nameof(types)); throw new ArgumentNullException(nameof(types));
var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainAssembly); var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainModule);
var decompileRun = new DecompileRun(settings) { var decompileRun = new DecompileRun(settings) {
DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(), DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(),
CancellationToken = CancellationToken CancellationToken = CancellationToken
@ -606,7 +606,7 @@ namespace ICSharpCode.Decompiler.CSharp
var type = typeSystem.Compilation.FindType(fullTypeName.TopLevelTypeName).GetDefinition(); var type = typeSystem.Compilation.FindType(fullTypeName.TopLevelTypeName).GetDefinition();
if (type == null) if (type == null)
throw new InvalidOperationException($"Could not find type definition {fullTypeName} in type system."); 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) { var decompileRun = new DecompileRun(settings) {
DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(), DocumentationProvider = DocumentationProvider ?? CreateDefaultDocumentationProvider(),
CancellationToken = CancellationToken CancellationToken = CancellationToken
@ -697,7 +697,7 @@ namespace ICSharpCode.Decompiler.CSharp
throw new NotSupportedException(entity.Kind.ToString()); 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; return syntaxTree;
} }
@ -776,7 +776,7 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
bool addNewModifier = false; bool addNewModifier = false;
var entity = (IEntity)member.GetSymbol(); 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); var baseTypes = entity.DeclaringType.GetNonInterfaceBaseTypes().Where(t => entity.DeclaringType != t);
if (entity is ITypeDefinition) { if (entity is ITypeDefinition) {

6
ICSharpCode.Decompiler/CSharp/CallBuilder.cs

@ -611,7 +611,7 @@ namespace ICSharpCode.Decompiler.CSharp
out IParameterizedMember foundMember) out IParameterizedMember foundMember)
{ {
foundMember = null; 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, var or = new OverloadResolution(resolver.Compilation,
arguments.SelectArray(a => a.ResolveResult), arguments.SelectArray(a => a.ResolveResult),
argumentNames: argumentNames, argumentNames: argumentNames,
@ -674,7 +674,7 @@ namespace ICSharpCode.Decompiler.CSharp
return false; return false;
foundMember = result.Member; foundMember = result.Member;
} else { } 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) { if (method.AccessorOwner.SymbolKind == SymbolKind.Indexer) {
var or = new OverloadResolution(resolver.Compilation, var or = new OverloadResolution(resolver.Compilation,
arguments.SelectArray(a => a.ResolveResult), arguments.SelectArray(a => a.ResolveResult),
@ -848,7 +848,7 @@ namespace ICSharpCode.Decompiler.CSharp
} }
MemberLookup lookup = null; MemberLookup lookup = null;
if (requireTarget) { 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) ; var rr = lookup.Lookup(target.ResolveResult, method.Name, method.TypeArguments, false) ;
needsCast = true; needsCast = true;
result = rr; result = rr;

4
ICSharpCode.Decompiler/CSharp/ExpressionBuilder.cs

@ -86,7 +86,7 @@ namespace ICSharpCode.Decompiler.CSharp
this.settings = settings; this.settings = settings;
this.cancellationToken = cancellationToken; this.cancellationToken = cancellationToken;
this.compilation = decompilationContext.Compilation; 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 = new TypeSystemAstBuilder(resolver);
this.astBuilder.AlwaysUseShortTypeNames = true; this.astBuilder.AlwaysUseShortTypeNames = true;
this.astBuilder.AddResolveResultAnnotations = true; this.astBuilder.AddResolveResultAnnotations = true;
@ -209,7 +209,7 @@ namespace ICSharpCode.Decompiler.CSharp
var result = resolver.ResolveSimpleName(field.Name, EmptyList<IType>.Instance, isInvocationTarget: false) as MemberResolveResult; var result = resolver.ResolveSimpleName(field.Name, EmptyList<IType>.Instance, isInvocationTarget: false) as MemberResolveResult;
return !(result == null || result.IsError || !result.Member.Equals(field, NormalizeTypeVisitor.TypeErasure)); return !(result == null || result.IsError || !result.Member.Equals(field, NormalizeTypeVisitor.TypeErasure));
} else { } 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<IType>.Instance, false) as MemberResolveResult; var result = lookup.Lookup(target.ResolveResult, field.Name, EmptyList<IType>.Instance, false) as MemberResolveResult;
return !(result == null || result.IsError || !result.Member.Equals(field, NormalizeTypeVisitor.TypeErasure)); return !(result == null || result.IsError || !result.Member.Equals(field, NormalizeTypeVisitor.TypeErasure));
} }

10
ICSharpCode.Decompiler/CSharp/RequiredNamespaceCollector.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.Decompiler.CSharp
{ {
public static void CollectNamespaces(DecompilerTypeSystem typeSystem, HashSet<string> namespaces) public static void CollectNamespaces(DecompilerTypeSystem typeSystem, HashSet<string> namespaces)
{ {
foreach (var type in typeSystem.MainAssembly.TypeDefinitions) { foreach (var type in typeSystem.MainModule.TypeDefinitions) {
CollectNamespaces(type, typeSystem, namespaces); CollectNamespaces(type, typeSystem, namespaces);
} }
CollectAttributeNamespaces(typeSystem, namespaces); CollectAttributeNamespaces(typeSystem, namespaces);
@ -30,8 +30,8 @@ namespace ICSharpCode.Decompiler.CSharp
public static void CollectAttributeNamespaces(DecompilerTypeSystem typeSystem, HashSet<string> namespaces) public static void CollectAttributeNamespaces(DecompilerTypeSystem typeSystem, HashSet<string> namespaces)
{ {
HandleAttributes(typeSystem.MainAssembly.GetAssemblyAttributes(), namespaces); HandleAttributes(typeSystem.MainModule.GetAssemblyAttributes(), namespaces);
HandleAttributes(typeSystem.MainAssembly.GetModuleAttributes(), namespaces); HandleAttributes(typeSystem.MainModule.GetModuleAttributes(), namespaces);
} }
public static void CollectNamespaces(IEntity entity, DecompilerTypeSystem typeSystem, public static void CollectNamespaces(IEntity entity, DecompilerTypeSystem typeSystem,
@ -42,7 +42,7 @@ namespace ICSharpCode.Decompiler.CSharp
switch (entity) { switch (entity) {
case ITypeDefinition td: case ITypeDefinition td:
if (mappingInfo == null) if (mappingInfo == null)
mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentAssembly.PEFile, entity.MetadataToken); mappingInfo = CSharpDecompiler.GetCodeMappingInfo(entity.ParentModule.PEFile, entity.MetadataToken);
namespaces.Add(td.Namespace); namespaces.Add(td.Namespace);
HandleAttributes(td.GetAttributes(), namespaces); HandleAttributes(td.GetAttributes(), namespaces);
@ -91,7 +91,7 @@ namespace ICSharpCode.Decompiler.CSharp
} }
if (!method.MetadataToken.IsNil && method.HasBody) { if (!method.MetadataToken.IsNil && method.HasBody) {
if (mappingInfo == null) 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 reader = typeSystem.ModuleDefinition.Reader;
var parts = mappingInfo.GetMethodParts((MethodDefinitionHandle)method.MetadataToken).ToList(); var parts = mappingInfo.GetMethodParts((MethodDefinitionHandle)method.MetadataToken).ToList();
foreach (var part in parts) { foreach (var part in parts) {

4
ICSharpCode.Decompiler/CSharp/Resolver/CSharpOperators.cs

@ -175,8 +175,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
get { return false; } get { return false; }
} }
IAssembly IEntity.ParentAssembly { IModule IEntity.ParentModule {
get { return compilation.MainAssembly; } get { return compilation.MainModule; }
} }
TypeParameterSubstitution IMember.Substitution { TypeParameterSubstitution IMember.Substitution {

12
ICSharpCode.Decompiler/CSharp/Resolver/CSharpResolver.cs

@ -52,7 +52,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
throw new ArgumentNullException("compilation"); throw new ArgumentNullException("compilation");
this.compilation = compilation; this.compilation = compilation;
this.conversions = CSharpConversions.Get(compilation); this.conversions = CSharpConversions.Get(compilation);
this.context = new CSharpTypeResolveContext(compilation.MainAssembly); this.context = new CSharpTypeResolveContext(compilation.MainModule);
} }
public CSharpResolver(CSharpTypeResolveContext context) public CSharpResolver(CSharpTypeResolveContext context)
@ -94,8 +94,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
get { return context; } get { return context; }
} }
IAssembly ITypeResolveContext.CurrentAssembly { IModule ITypeResolveContext.CurrentModule {
get { return context.CurrentAssembly; } get { return context.CurrentModule; }
} }
CSharpResolver WithContext(CSharpTypeResolveContext newContext) CSharpResolver WithContext(CSharpTypeResolveContext newContext)
@ -1536,7 +1536,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
bool TopLevelTypeDefinitionIsAccessible(ITypeDefinition typeDef) bool TopLevelTypeDefinitionIsAccessible(ITypeDefinition typeDef)
{ {
if (typeDef.Accessibility == Accessibility.Internal) { if (typeDef.Accessibility == Accessibility.Internal) {
return typeDef.ParentAssembly.InternalsVisibleTo(compilation.MainAssembly); return typeDef.ParentModule.InternalsVisibleTo(compilation.MainModule);
} }
return true; return true;
} }
@ -1651,7 +1651,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
ITypeDefinition currentTypeDefinition = this.CurrentTypeDefinition; ITypeDefinition currentTypeDefinition = this.CurrentTypeDefinition;
bool isInEnumMemberInitializer = this.CurrentMember != null && this.CurrentMember.SymbolKind == SymbolKind.Field bool isInEnumMemberInitializer = this.CurrentMember != null && this.CurrentMember.SymbolKind == SymbolKind.Field
&& currentTypeDefinition != null && currentTypeDefinition.Kind == TypeKind.Enum; && currentTypeDefinition != null && currentTypeDefinition.Kind == TypeKind.Enum;
return new MemberLookup(currentTypeDefinition, this.Compilation.MainAssembly, isInEnumMemberInitializer); return new MemberLookup(currentTypeDefinition, this.Compilation.MainModule, isInEnumMemberInitializer);
} }
/// <summary> /// <summary>
@ -1664,7 +1664,7 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// for accessibility purposes. // for accessibility purposes.
// This avoids a stack overflow when referencing a protected class nested inside the base class // This avoids a stack overflow when referencing a protected class nested inside the base class
// of a parent class. (NameLookupTests.InnerClassInheritingFromProtectedBaseInnerClassShouldNotCauseStackOverflow) // 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 { } else {
return CreateMemberLookup(); return CreateMemberLookup();
} }

16
ICSharpCode.Decompiler/CSharp/Resolver/MemberLookup.cs

@ -47,13 +47,13 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
#endregion #endregion
readonly ITypeDefinition currentTypeDefinition; readonly ITypeDefinition currentTypeDefinition;
readonly IAssembly currentAssembly; readonly IModule currentModule;
readonly bool isInEnumMemberInitializer; 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.currentTypeDefinition = currentTypeDefinition;
this.currentAssembly = currentAssembly; this.currentModule = currentModule;
this.isInEnumMemberInitializer = isInEnumMemberInitializer; this.isInEnumMemberInitializer = isInEnumMemberInitializer;
} }
@ -116,19 +116,19 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
case Accessibility.Protected: case Accessibility.Protected:
return IsProtectedAccessible(allowProtectedAccess, entity); return IsProtectedAccessible(allowProtectedAccess, entity);
case Accessibility.Internal: case Accessibility.Internal:
return IsInternalAccessible(entity.ParentAssembly); return IsInternalAccessible(entity.ParentModule);
case Accessibility.ProtectedOrInternal: case Accessibility.ProtectedOrInternal:
return IsInternalAccessible(entity.ParentAssembly) || IsProtectedAccessible(allowProtectedAccess, entity); return IsInternalAccessible(entity.ParentModule) || IsProtectedAccessible(allowProtectedAccess, entity);
case Accessibility.ProtectedAndInternal: case Accessibility.ProtectedAndInternal:
return IsInternalAccessible(entity.ParentAssembly) && IsProtectedAccessible(allowProtectedAccess, entity); return IsInternalAccessible(entity.ParentModule) && IsProtectedAccessible(allowProtectedAccess, entity);
default: default:
throw new Exception("Invalid value for Accessibility"); 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) bool IsProtectedAccessible(bool allowProtectedAccess, IEntity entity)

4
ICSharpCode.Decompiler/CSharp/Resolver/ReducedExtensionMethod.cs

@ -231,9 +231,9 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} }
} }
public IAssembly ParentAssembly { public IModule ParentModule {
get { get {
return baseMethod.ParentAssembly; return baseMethod.ParentModule;
} }
} }

2
ICSharpCode.Decompiler/CSharp/Syntax/TypeSystemAstBuilder.cs

@ -204,7 +204,7 @@ namespace ICSharpCode.Decompiler.CSharp.Syntax
public AstType ConvertType(FullTypeName fullTypeName) public AstType ConvertType(FullTypeName fullTypeName)
{ {
if (resolver != null) { if (resolver != null) {
foreach (var asm in resolver.Compilation.Assemblies) { foreach (var asm in resolver.Compilation.Modules) {
var def = asm.GetTypeDefinition(fullTypeName); var def = asm.GetTypeDefinition(fullTypeName);
if (def != null) { if (def != null) {
return ConvertType(def); return ConvertType(def);

4
ICSharpCode.Decompiler/CSharp/Transforms/IntroduceExtensionMethods.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
usingScope = new UsingScope(usingScope, ns); 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.resolveContextStack.Push(currentContext);
this.resolver = new CSharpResolver(currentContext); this.resolver = new CSharpResolver(currentContext);
} }
@ -68,7 +68,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
foreach (string ident in namespaceDeclaration.Identifiers) { foreach (string ident in namespaceDeclaration.Identifiers) {
usingScope = new UsingScope(usingScope, ident); 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); resolveContextStack.Push(currentContext);
try { try {
this.resolver = new CSharpResolver(currentContext); this.resolver = new CSharpResolver(currentContext);

6
ICSharpCode.Decompiler/CSharp/Transforms/IntroduceUsingDeclarations.cs

@ -130,7 +130,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
usingScope = new UsingScope(usingScope, ns); 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.context.Push(currentContext);
this.astBuilder = CreateAstBuilder(currentContext); this.astBuilder = CreateAstBuilder(currentContext);
} }
@ -150,7 +150,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
foreach (string ident in namespaceDeclaration.Identifiers) { foreach (string ident in namespaceDeclaration.Identifiers) {
usingScope = new UsingScope(usingScope, ident); 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); context.Push(currentContext);
try { try {
astBuilder = CreateAstBuilder(currentContext); astBuilder = CreateAstBuilder(currentContext);
@ -179,7 +179,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
{ {
if (methodDeclaration.GetSymbol() is IMethod method && CSharpDecompiler.IsWindowsFormsInitializeComponentMethod(method)) { if (methodDeclaration.GetSymbol() is IMethod method && CSharpDecompiler.IsWindowsFormsInitializeComponentMethod(method)) {
var previousContext = context.Peek(); var previousContext = context.Peek();
var currentContext = new CSharpTypeResolveContext(previousContext.CurrentAssembly); var currentContext = new CSharpTypeResolveContext(previousContext.CurrentModule);
context.Push(currentContext); context.Push(currentContext);
try { try {
astBuilder = CreateAstBuilder(currentContext); astBuilder = CreateAstBuilder(currentContext);

6
ICSharpCode.Decompiler/CSharp/Transforms/TransformContext.cs

@ -51,10 +51,10 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
} }
/// <summary> /// <summary>
/// Returns the assembly that is being decompiled. /// Returns the module that is being decompiled.
/// </summary> /// </summary>
public IAssembly DecompiledAssembly { public IModule DecompiledModule {
get { return decompilationContext.CurrentAssembly; } get { return decompilationContext.CurrentModule; }
} }
/// <summary> /// <summary>

26
ICSharpCode.Decompiler/CSharp/TypeSystem/CSharpTypeResolveContext.cs

@ -23,25 +23,25 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
{ {
public sealed class CSharpTypeResolveContext : ITypeResolveContext public sealed class CSharpTypeResolveContext : ITypeResolveContext
{ {
readonly IAssembly assembly; readonly IModule module;
readonly ResolvedUsingScope currentUsingScope; readonly ResolvedUsingScope currentUsingScope;
readonly ITypeDefinition currentTypeDefinition; readonly ITypeDefinition currentTypeDefinition;
readonly IMember currentMember; readonly IMember currentMember;
readonly string[] methodTypeParameterNames; 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) if (module == null)
throw new ArgumentNullException("assembly"); throw new ArgumentNullException(nameof(module));
this.assembly = assembly; this.module = module;
this.currentUsingScope = usingScope; this.currentUsingScope = usingScope;
this.currentTypeDefinition = typeDefinition; this.currentTypeDefinition = typeDefinition;
this.currentMember = member; 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.currentUsingScope = usingScope;
this.currentTypeDefinition = typeDefinition; this.currentTypeDefinition = typeDefinition;
this.currentMember = member; this.currentMember = member;
@ -53,11 +53,11 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
} }
public ICompilation Compilation { public ICompilation Compilation {
get { return assembly.Compilation; } get { return module.Compilation; }
} }
public IAssembly CurrentAssembly { public IModule CurrentModule {
get { return assembly; } get { return module; }
} }
public ITypeDefinition CurrentTypeDefinition { public ITypeDefinition CurrentTypeDefinition {
@ -70,7 +70,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
public CSharpTypeResolveContext WithCurrentTypeDefinition(ITypeDefinition typeDefinition) 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) ITypeResolveContext ITypeResolveContext.WithCurrentTypeDefinition(ITypeDefinition typeDefinition)
@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
public CSharpTypeResolveContext WithCurrentMember(IMember member) 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) ITypeResolveContext ITypeResolveContext.WithCurrentMember(IMember member)
@ -90,7 +90,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
public CSharpTypeResolveContext WithUsingScope(ResolvedUsingScope usingScope) public CSharpTypeResolveContext WithUsingScope(ResolvedUsingScope usingScope)
{ {
return new CSharpTypeResolveContext(assembly, usingScope, currentTypeDefinition, currentMember, methodTypeParameterNames); return new CSharpTypeResolveContext(module, usingScope, currentTypeDefinition, currentMember, methodTypeParameterNames);
} }
} }
} }

4
ICSharpCode.Decompiler/CSharp/TypeSystem/ResolvedUsingScope.cs

@ -184,8 +184,8 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
get { return EmptyList<ITypeDefinition>.Instance; } get { return EmptyList<ITypeDefinition>.Instance; }
} }
IEnumerable<IAssembly> INamespace.ContributingAssemblies { IEnumerable<IModule> INamespace.ContributingModules {
get { return EmptyList<IAssembly>.Instance; } get { return EmptyList<IModule>.Instance; }
} }
ICompilation ICompilationProvider.Compilation { ICompilation ICompilationProvider.Compilation {

2
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. // nested compilation and not in this, we wouldn't be able to map it anyways.
var ctx = context as CSharpTypeResolveContext; var ctx = context as CSharpTypeResolveContext;
if (ctx == null) { 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)); return ResolveType(new CSharpResolver(ctx));

2
ICSharpCode.Decompiler/CSharp/TypeSystem/UsingScope.cs

@ -154,7 +154,7 @@ namespace ICSharpCode.Decompiler.CSharp.TypeSystem
CacheManager cache = compilation.CacheManager; CacheManager cache = compilation.CacheManager;
ResolvedUsingScope resolved = cache.GetShared(this) as ResolvedUsingScope; ResolvedUsingScope resolved = cache.GetShared(this) as ResolvedUsingScope;
if (resolved == null) { 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)); resolved = (ResolvedUsingScope)cache.GetOrAddShared(this, new ResolvedUsingScope(csContext, this));
} }
return resolved; return resolved;

6
ICSharpCode.Decompiler/DebugInfo/PortablePdbWriter.cs

@ -126,13 +126,13 @@ namespace ICSharpCode.Decompiler.DebugInfo
if (scope == null) if (scope == null)
return default; return default;
Dictionary<IAssembly, AssemblyReferenceHandle> assemblyReferences = new Dictionary<IAssembly, AssemblyReferenceHandle>(); Dictionary<IModule, AssemblyReferenceHandle> assemblyReferences = new Dictionary<IModule, AssemblyReferenceHandle>();
var writer = new BlobBuilder(); var writer = new BlobBuilder();
foreach (var import in scope.Usings) { foreach (var import in scope.Usings) {
foreach (var asm in import.ContributingAssemblies) { foreach (var asm in import.ContributingModules) {
if (asm == compilation.MainAssembly) { if (asm == compilation.MainModule) {
writer.WriteByte(1); writer.WriteByte(1);
writer.WriteCompressedInteger(MetadataTokens.GetHeapOffset(metadata.GetOrAddBlobUTF8(import.FullName))); writer.WriteCompressedInteger(MetadataTokens.GetHeapOffset(metadata.GetOrAddBlobUTF8(import.FullName)));
} else { } else {

2
ICSharpCode.Decompiler/Documentation/GetPotentiallyNestedClassTypeReference.cs

@ -44,7 +44,7 @@ namespace ICSharpCode.Decompiler.Documentation
public IType Resolve(ITypeResolveContext context) public IType Resolve(ITypeResolveContext context)
{ {
string[] parts = typeName.Split('.'); 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--) { for (int i = parts.Length - 1; i >= 0; i--) {
string ns = string.Join(".", parts, 0, i); string ns = string.Join(".", parts, 0, i);
string name = parts[i]; string name = parts[i];

11
ICSharpCode.Decompiler/Documentation/IdStringProvider.cs

@ -18,6 +18,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text; using System.Text;
using ICSharpCode.Decompiler.TypeSystem; using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.Decompiler.TypeSystem.Implementation; using ICSharpCode.Decompiler.TypeSystem.Implementation;
@ -61,10 +62,10 @@ namespace ICSharpCode.Decompiler.Documentation
AppendTypeName(b, member.DeclaringType, false); AppendTypeName(b, member.DeclaringType, false);
b.Append('.'); b.Append('.');
} }
/*if (member.IsExplicitInterfaceImplementation && member.Name.IndexOf('.') < 0 && member.ImplementedInterfaceMembers.Count == 1) { if (member.IsExplicitInterfaceImplementation && member.Name.IndexOf('.') < 0 && member.ExplicitlyImplementedInterfaceMembers.Count() == 1) {
AppendTypeName(b, member.ImplementedInterfaceMembers[0].DeclaringType, true); AppendTypeName(b, member.ExplicitlyImplementedInterfaceMembers.First().DeclaringType, true);
b.Append('#'); b.Append('#');
}*/ }
b.Append(member.Name.Replace('.', '#')); b.Append(member.Name.Replace('.', '#'));
IMethod method = member as IMethod; IMethod method = member as IMethod;
if (method != null && method.TypeParameters.Count > 0) { if (method != null && method.TypeParameters.Count > 0) {
@ -186,7 +187,7 @@ namespace ICSharpCode.Decompiler.Documentation
/// <returns>A member reference that represents the ID string.</returns> /// <returns>A member reference that represents the ID string.</returns>
/// <exception cref="ReflectionNameParseException">The syntax of the ID string is invalid</exception> /// <exception cref="ReflectionNameParseException">The syntax of the ID string is invalid</exception>
/// <remarks> /// <remarks>
/// The member reference will look in <see cref="ITypeResolveContext.CurrentAssembly"/> first, /// The member reference will look in <see cref="ITypeResolveContext.CurrentModule"/> first,
/// and if the member is not found there, /// and if the member is not found there,
/// it will look in all other assemblies of the compilation. /// it will look in all other assemblies of the compilation.
/// </remarks> /// </remarks>
@ -228,7 +229,7 @@ namespace ICSharpCode.Decompiler.Documentation
/// <exception cref="ReflectionNameParseException">The syntax of the ID string is invalid</exception> /// <exception cref="ReflectionNameParseException">The syntax of the ID string is invalid</exception>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// The type reference will look in <see cref="ITypeResolveContext.CurrentAssembly"/> first, /// The type reference will look in <see cref="ITypeResolveContext.CurrentModule"/> first,
/// and if the type is not found there, /// and if the type is not found there,
/// it will look in all other assemblies of the compilation. /// it will look in all other assemblies of the compilation.
/// </para> /// </para>

4
ICSharpCode.Decompiler/Documentation/XmlDocKeyProvider.cs

@ -186,7 +186,7 @@ namespace ICSharpCode.Decompiler.Documentation
/// <returns>A member reference that represents the ID string.</returns> /// <returns>A member reference that represents the ID string.</returns>
/// <exception cref="ReflectionNameParseException">The syntax of the ID string is invalid</exception> /// <exception cref="ReflectionNameParseException">The syntax of the ID string is invalid</exception>
/// <remarks> /// <remarks>
/// The member reference will look in <see cref="ITypeResolveContext.CurrentAssembly"/> first, /// The member reference will look in <see cref="ITypeResolveContext.CurrentModule"/> first,
/// and if the member is not found there, /// and if the member is not found there,
/// it will look in all other assemblies of the compilation. /// it will look in all other assemblies of the compilation.
/// </remarks> /// </remarks>
@ -228,7 +228,7 @@ namespace ICSharpCode.Decompiler.Documentation
/// <exception cref="ReflectionNameParseException">The syntax of the ID string is invalid</exception> /// <exception cref="ReflectionNameParseException">The syntax of the ID string is invalid</exception>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// The type reference will look in <see cref="ITypeResolveContext.CurrentAssembly"/> first, /// The type reference will look in <see cref="ITypeResolveContext.CurrentModule"/> first,
/// and if the type is not found there, /// and if the type is not found there,
/// it will look in all other assemblies of the compilation. /// it will look in all other assemblies of the compilation.
/// </para> /// </para>

4
ICSharpCode.Decompiler/ICSharpCode.Decompiler.csproj

@ -360,9 +360,9 @@
<Compile Include="TypeSystem\Implementation\MetadataTypeDefinition.cs" /> <Compile Include="TypeSystem\Implementation\MetadataTypeDefinition.cs" />
<Compile Include="TypeSystem\Implementation\MetadataTypeParameter.cs" /> <Compile Include="TypeSystem\Implementation\MetadataTypeParameter.cs" />
<Compile Include="TypeSystem\Implementation\SpecializedParameter.cs" /> <Compile Include="TypeSystem\Implementation\SpecializedParameter.cs" />
<Compile Include="TypeSystem\MetadataAssembly.cs" /> <Compile Include="TypeSystem\MetadataModule.cs" />
<Compile Include="TypeSystem\ModifiedType.cs" /> <Compile Include="TypeSystem\ModifiedType.cs" />
<Compile Include="TypeSystem\Implementation\TypeSpecification.cs" /> <Compile Include="TypeSystem\Implementation\PinnedType.cs" />
<Compile Include="Metadata\MetadataExtensions.cs" /> <Compile Include="Metadata\MetadataExtensions.cs" />
<Compile Include="Semantics\TupleResolveResult.cs" /> <Compile Include="Semantics\TupleResolveResult.cs" />
<Compile Include="TypeSystem\NormalizeTypeVisitor.cs" /> <Compile Include="TypeSystem\NormalizeTypeVisitor.cs" />

2
ICSharpCode.Decompiler/IL/Transforms/NullPropagationTransform.cs

@ -260,7 +260,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
{ {
return CSharp.Transforms.IntroduceExtensionMethods.CanTransformToExtensionMethodCall( return CSharp.Transforms.IntroduceExtensionMethods.CanTransformToExtensionMethodCall(
call.Method, new CSharp.TypeSystem.CSharpTypeResolveContext( call.Method, new CSharp.TypeSystem.CSharpTypeResolveContext(
context.TypeSystem.Compilation.MainAssembly, context.UsingScope context.TypeSystem.Compilation.MainModule, context.UsingScope
) )
); );
} }

2
ICSharpCode.Decompiler/IL/Transforms/TransformCollectionAndObjectInitializers.cs

@ -178,7 +178,7 @@ namespace ICSharpCode.Decompiler.IL.Transforms
possibleIndexVariables.Add(stloc.Variable, (stloc.ChildIndex, stloc.Value)); possibleIndexVariables.Add(stloc.Variable, (stloc.ChildIndex, stloc.Value));
return true; 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); (var kind, var newPath, var values, var targetVariable) = AccessPathElement.GetAccessPath(instructions[pos], rootType, context.Settings, resolveContext, possibleIndexVariables);
if (kind == AccessPathKind.Invalid || target != targetVariable) if (kind == AccessPathKind.Invalid || target != targetVariable)
return false; return false;

4
ICSharpCode.Decompiler/Metadata/MetadataExtensions.cs

@ -89,12 +89,12 @@ namespace ICSharpCode.Decompiler.Metadata
return Disassembler.DisassemblerHelpers.Escape(name); 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); var tr = reader.GetTypeReference(handle);
switch (tr.ResolutionScope.Kind) { switch (tr.ResolutionScope.Kind) {
case HandleKind.TypeReference: case HandleKind.TypeReference:
return ((TypeReferenceHandle)tr.ResolutionScope).GetDeclaringAssembly(reader); return ((TypeReferenceHandle)tr.ResolutionScope).GetDeclaringModule(reader);
case HandleKind.AssemblyReference: case HandleKind.AssemblyReference:
var asmRef = reader.GetAssemblyReference((AssemblyReferenceHandle)tr.ResolutionScope); var asmRef = reader.GetAssemblyReference((AssemblyReferenceHandle)tr.ResolutionScope);
return new DefaultAssemblyReference(reader.GetString(asmRef.Name)); return new DefaultAssemblyReference(reader.GetString(asmRef.Name));

27
ICSharpCode.Decompiler/Metadata/PEFile.cs

@ -28,7 +28,20 @@ using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.Decompiler.Metadata namespace ICSharpCode.Decompiler.Metadata
{ {
public class PEFile : IDisposable, TypeSystem.IAssemblyReference /// <summary>
/// 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 <see cref="MetadataModule"/> class is used instead.
/// </summary>
/// <remarks>
/// In addition to wrapping a <c>System.Reflection.Metadata.PEReader</c>, 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.
/// </remarks>
public class PEFile : IDisposable, TypeSystem.IModuleReference
{ {
public string FileName { get; } public string FileName { get; }
public PEReader Reader { 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); 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 PEFile peFile;
readonly TypeSystemOptions options; readonly TypeSystemOptions options;
@ -178,9 +191,9 @@ namespace ICSharpCode.Decompiler.Metadata
this.options = options; 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);
} }
} }
} }

4
ICSharpCode.Decompiler/SRMExtensions.cs

@ -403,7 +403,7 @@ namespace ICSharpCode.Decompiler
var typeDef = typeSystem.ResolveAsType(handle).GetDefinition(); var typeDef = typeSystem.ResolveAsType(handle).GetDefinition();
if (typeDef == null || typeDef.MetadataToken.IsNil) if (typeDef == null || typeDef.MetadataToken.IsNil)
return 0; return 0;
reader = typeDef.ParentAssembly.PEFile.Metadata; reader = typeDef.ParentModule.PEFile.Metadata;
var td = reader.GetTypeDefinition((TypeDefinitionHandle)typeDef.MetadataToken); var td = reader.GetTypeDefinition((TypeDefinitionHandle)typeDef.MetadataToken);
return td.GetLayout().Size; return td.GetLayout().Size;
} }
@ -413,7 +413,7 @@ namespace ICSharpCode.Decompiler
var typeDef = typeSystem.ResolveAsType(handle).GetDefinition(); var typeDef = typeSystem.ResolveAsType(handle).GetDefinition();
if (typeDef == null || typeDef.MetadataToken.IsNil) if (typeDef == null || typeDef.MetadataToken.IsNil)
return 0; return 0;
reader = typeDef.ParentAssembly.PEFile.Metadata; reader = typeDef.ParentModule.PEFile.Metadata;
var td = reader.GetTypeDefinition((TypeDefinitionHandle)typeDef.MetadataToken); var td = reader.GetTypeDefinition((TypeDefinitionHandle)typeDef.MetadataToken);
return td.GetLayout().Size; return td.GetLayout().Size;
} }

2
ICSharpCode.Decompiler/TypeSystem/ApplyAttributeTypeVisitor.cs

@ -126,7 +126,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
{ {
if (useTupleTypes && TupleType.IsTupleCompatible(type, out int tupleCardinality)) { if (useTupleTypes && TupleType.IsTupleCompatible(type, out int tupleCardinality)) {
if (tupleCardinality > 1) { if (tupleCardinality > 1) {
var valueTupleAssembly = type.GetDefinition()?.ParentAssembly; var valueTupleAssembly = type.GetDefinition()?.ParentModule;
ImmutableArray<string> elementNames = default; ImmutableArray<string> elementNames = default;
if (tupleElementNames != null && tupleTypeIndex < tupleElementNames.Length) { if (tupleElementNames != null && tupleTypeIndex < tupleElementNames.Length) {
string[] extractedValues = new string[tupleCardinality]; string[] extractedValues = new string[tupleCardinality];

2
ICSharpCode.Decompiler/TypeSystem/AssemblyQualifiedTypeName.cs

@ -33,7 +33,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public AssemblyQualifiedTypeName(ITypeDefinition typeDefinition) public AssemblyQualifiedTypeName(ITypeDefinition typeDefinition)
{ {
this.AssemblyName = typeDefinition.ParentAssembly.AssemblyName; this.AssemblyName = typeDefinition.ParentModule.AssemblyName;
this.TypeName = typeDefinition.FullTypeName; this.TypeName = typeDefinition.FullTypeName;
} }

32
ICSharpCode.Decompiler/TypeSystem/DecompilerTypeSystem.cs

@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
readonly ICompilation compilation; readonly ICompilation compilation;
readonly IAssemblyResolver assemblyResolver; readonly IAssemblyResolver assemblyResolver;
readonly TypeSystemOptions typeSystemOptions; readonly TypeSystemOptions typeSystemOptions;
readonly MetadataAssembly mainAssembly; readonly MetadataModule mainModule;
public DecompilerTypeSystem(Metadata.PEFile moduleDefinition, IAssemblyResolver assemblyResolver) public DecompilerTypeSystem(Metadata.PEFile moduleDefinition, IAssemblyResolver assemblyResolver)
: this(moduleDefinition, assemblyResolver, new DecompilerSettings()) : this(moduleDefinition, assemblyResolver, new DecompilerSettings())
@ -103,7 +103,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
var mainAssembly = moduleDefinition.WithOptions(typeSystemOptions); var mainAssembly = moduleDefinition.WithOptions(typeSystemOptions);
// Load referenced assemblies and type-forwarder references. // Load referenced assemblies and type-forwarder references.
// This is necessary to make .NET Core/PCL binaries work better. // This is necessary to make .NET Core/PCL binaries work better.
var referencedAssemblies = new List<IAssemblyReference>(); var referencedAssemblies = new List<IModuleReference>();
var assemblyReferenceQueue = new Queue<(bool IsAssembly, PEFile MainModule, object Reference)>(); var assemblyReferenceQueue = new Queue<(bool IsAssembly, PEFile MainModule, object Reference)>();
var mainMetadata = moduleDefinition.Metadata; var mainMetadata = moduleDefinition.Metadata;
foreach (var h in mainMetadata.GetModuleReferences()) { foreach (var h in mainMetadata.GetModuleReferences()) {
@ -158,15 +158,15 @@ namespace ICSharpCode.Decompiler.TypeSystem
referencedAssemblies.Add(MinimalCorlib.Instance); referencedAssemblies.Add(MinimalCorlib.Instance);
compilation = new SimpleCompilation(mainAssembly, referencedAssemblies); compilation = new SimpleCompilation(mainAssembly, referencedAssemblies);
} }
this.mainAssembly = (MetadataAssembly)compilation.MainAssembly; this.mainModule = (MetadataModule)compilation.MainModule;
} }
public ICompilation Compilation { public ICompilation Compilation {
get { return compilation; } get { return compilation; }
} }
public MetadataAssembly MainAssembly { public MetadataModule MainModule {
get { return mainAssembly; } get { return mainModule; }
} }
public Metadata.PEFile ModuleDefinition { public Metadata.PEFile ModuleDefinition {
@ -175,14 +175,6 @@ namespace ICSharpCode.Decompiler.TypeSystem
public SRM.MetadataReader GetMetadata() => moduleDefinition.Metadata; 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) public IMember ResolveAsMember(SRM.EntityHandle memberReference)
{ {
switch (memberReference.Kind) { switch (memberReference.Kind) {
@ -212,27 +204,27 @@ namespace ICSharpCode.Decompiler.TypeSystem
public IType ResolveAsType(SRM.EntityHandle typeReference) public IType ResolveAsType(SRM.EntityHandle typeReference)
{ {
return mainAssembly.ResolveType(typeReference, new GenericContext()); return mainModule.ResolveType(typeReference, new GenericContext());
} }
public IMethod ResolveAsMethod(SRM.EntityHandle methodReference) public IMethod ResolveAsMethod(SRM.EntityHandle methodReference)
{ {
return mainAssembly.ResolveMethod(methodReference); return mainModule.ResolveMethod(methodReference);
} }
public IField ResolveAsField(SRM.EntityHandle fieldReference) 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) 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) 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<IType> DecodeMethodSignature(SRM.StandaloneSignatureHandle handle) public SRM.MethodSignature<IType> DecodeMethodSignature(SRM.StandaloneSignatureHandle handle)
@ -241,7 +233,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
if (standaloneSignature.GetKind() != SRM.StandaloneSignatureKind.Method) if (standaloneSignature.GetKind() != SRM.StandaloneSignatureKind.Method)
throw new InvalidOperationException("Expected Method signature"); throw new InvalidOperationException("Expected Method signature");
var sig = standaloneSignature.DecodeMethodSignature( var sig = standaloneSignature.DecodeMethodSignature(
mainAssembly.TypeProvider, mainModule.TypeProvider,
new GenericContext() new GenericContext()
); );
return new SRM.MethodSignature<IType>( return new SRM.MethodSignature<IType>(
@ -261,7 +253,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
if (standaloneSignature.GetKind() != SRM.StandaloneSignatureKind.LocalVariables) if (standaloneSignature.GetKind() != SRM.StandaloneSignatureKind.LocalVariables)
throw new InvalidOperationException("Expected Local signature"); throw new InvalidOperationException("Expected Local signature");
var types = standaloneSignature.DecodeLocalSignature( var types = standaloneSignature.DecodeLocalSignature(
mainAssembly.TypeProvider, mainModule.TypeProvider,
new GenericContext() new GenericContext()
); );
return ImmutableArray.CreateRange(types, ApplyAttributesToType); return ImmutableArray.CreateRange(types, ApplyAttributesToType);

32
ICSharpCode.Decompiler/TypeSystem/IAssembly.cs

@ -17,23 +17,35 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection.Metadata;
using ICSharpCode.Decompiler.Metadata; using ICSharpCode.Decompiler.Metadata;
namespace ICSharpCode.Decompiler.TypeSystem namespace ICSharpCode.Decompiler.TypeSystem
{ {
public interface IAssemblyReference /// <summary>
/// Interface used to help with construction of the type system.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
public interface IModuleReference
{ {
/// <summary> /// <summary>
/// Resolves this assembly. /// Resolves this metadata module.
/// </summary> /// </summary>
IAssembly Resolve(ITypeResolveContext context); IModule Resolve(ITypeResolveContext context);
} }
/// <summary> /// <summary>
/// Represents an assembly. /// Represents a metadata module.
/// </summary> /// </summary>
public interface IAssembly : ICompilationProvider public interface IModule : ICompilationProvider
{ {
/// <summary> /// <summary>
/// Gets the underlying metadata file. May return null, if the IAssembly was not created from a PE file. /// 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
/// <summary> /// <summary>
/// Gets whether this assembly is the main assembly of the compilation. /// Gets whether this assembly is the main assembly of the compilation.
/// </summary> /// </summary>
bool IsMainAssembly { get; } bool IsMainModule { get; }
/// <summary> /// <summary>
/// Gets the assembly name (short name). /// Gets the assembly name (short name).
@ -68,13 +80,15 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// <summary> /// <summary>
/// Gets whether the internals of this assembly are visible in the specified assembly. /// Gets whether the internals of this assembly are visible in the specified assembly.
/// </summary> /// </summary>
bool InternalsVisibleTo(IAssembly assembly); bool InternalsVisibleTo(IModule module);
/// <summary> /// <summary>
/// Gets the root namespace for this assembly. /// Gets the root namespace for this module.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This always is the namespace without a name - it's unrelated to the 'root namespace' project setting. /// 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.
/// </remarks> /// </remarks>
INamespace RootNamespace { get; } INamespace RootNamespace { get; }

18
ICSharpCode.Decompiler/TypeSystem/ICompilation.cs

@ -25,9 +25,11 @@ namespace ICSharpCode.Decompiler.TypeSystem
public interface ICompilation public interface ICompilation
{ {
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
IAssembly MainAssembly { get; } IModule MainModule { get; }
/// <summary> /// <summary>
/// Gets the type resolve context that specifies this compilation and no current assembly or entity. /// Gets the type resolve context that specifies this compilation and no current assembly or entity.
@ -35,18 +37,18 @@ namespace ICSharpCode.Decompiler.TypeSystem
ITypeResolveContext TypeResolveContext { get; } ITypeResolveContext TypeResolveContext { get; }
/// <summary> /// <summary>
/// Gets the list of all assemblies in the compilation. /// Gets the list of all modules in the compilation.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// This main assembly is the first entry in the list. /// This main module is the first entry in the list.
/// </remarks> /// </remarks>
IList<IAssembly> Assemblies { get; } IList<IModule> Modules { get; }
/// <summary> /// <summary>
/// Gets the referenced assemblies. /// Gets the referenced modules.
/// This list does not include the main assembly. /// This list does not include the main module.
/// </summary> /// </summary>
IList<IAssembly> ReferencedAssemblies { get; } IList<IModule> ReferencedModules { get; }
/// <summary> /// <summary>
/// Gets the root namespace of this compilation. /// Gets the root namespace of this compilation.

2
ICSharpCode.Decompiler/TypeSystem/IDecompilerTypeSystem.cs

@ -28,6 +28,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public interface IDecompilerTypeSystem public interface IDecompilerTypeSystem
{ {
ICompilation Compilation { get; } ICompilation Compilation { get; }
MetadataModule MainModule { get; }
MethodSignature<IType> DecodeMethodSignature(StandaloneSignatureHandle standaloneSignatureHandle); MethodSignature<IType> DecodeMethodSignature(StandaloneSignatureHandle standaloneSignatureHandle);
ImmutableArray<IType> DecodeLocalSignature(StandaloneSignatureHandle standaloneSignatureHandle); ImmutableArray<IType> DecodeLocalSignature(StandaloneSignatureHandle standaloneSignatureHandle);
@ -39,7 +40,6 @@ namespace ICSharpCode.Decompiler.TypeSystem
MetadataReader GetMetadata(); MetadataReader GetMetadata();
PEFile ModuleDefinition { get; } PEFile ModuleDefinition { get; }
PEFile GetModuleDefinition(IAssembly assembly);
/// <summary> /// <summary>
/// Gets a type system instance that automatically specializes the results /// Gets a type system instance that automatically specializes the results

5
ICSharpCode.Decompiler/TypeSystem/IEntity.cs

@ -56,10 +56,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
IType DeclaringType { get; } IType DeclaringType { get; }
/// <summary> /// <summary>
/// The assembly in which this entity is defined. /// The module in which this entity is defined.
/// This property never returns null.
/// </summary> /// </summary>
IAssembly ParentAssembly { get; } IModule ParentModule { get; }
/// <summary> /// <summary>
/// Gets the attributes on this entity. /// Gets the attributes on this entity.

4
ICSharpCode.Decompiler/TypeSystem/INamespace.cs

@ -62,9 +62,9 @@ namespace ICSharpCode.Decompiler.TypeSystem
IEnumerable<ITypeDefinition> Types { get; } IEnumerable<ITypeDefinition> Types { get; }
/// <summary> /// <summary>
/// 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).
/// </summary> /// </summary>
IEnumerable<IAssembly> ContributingAssemblies { get; } IEnumerable<IModule> ContributingModules { get; }
/// <summary> /// <summary>
/// Gets a direct child namespace by its short name. /// Gets a direct child namespace by its short name.

6
ICSharpCode.Decompiler/TypeSystem/ITypeReference.cs

@ -50,10 +50,10 @@ namespace ICSharpCode.Decompiler.TypeSystem
public interface ITypeResolveContext : ICompilationProvider public interface ITypeResolveContext : ICompilationProvider
{ {
/// <summary> /// <summary>
/// Gets the current assembly. /// Gets the current module.
/// This property may return null if this context does not specify any assembly. /// This property may return null if this context does not specify any module.
/// </summary> /// </summary>
IAssembly CurrentAssembly { get; } IModule CurrentModule { get; }
/// <summary> /// <summary>
/// Gets the current type definition. /// Gets the current type definition.

56
ICSharpCode.Decompiler/TypeSystem/Implementation/AttributeListBuilder.cs

@ -32,20 +32,20 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{ {
readonly struct AttributeListBuilder readonly struct AttributeListBuilder
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly List<IAttribute> attributes; readonly List<IAttribute> attributes;
public AttributeListBuilder(MetadataAssembly assembly) public AttributeListBuilder(MetadataModule module)
{ {
Debug.Assert(assembly != null); Debug.Assert(module != null);
this.assembly = assembly; this.module = module;
this.attributes = new List<IAttribute>(); this.attributes = new List<IAttribute>();
} }
public AttributeListBuilder(MetadataAssembly assembly, int capacity) public AttributeListBuilder(MetadataModule module, int capacity)
{ {
Debug.Assert(assembly != null); Debug.Assert(module != null);
this.assembly = assembly; this.module = module;
this.attributes = new List<IAttribute>(capacity); this.attributes = new List<IAttribute>(capacity);
} }
@ -60,7 +60,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public void Add(KnownAttribute type) public void Add(KnownAttribute type)
{ {
// use the assemblies' cache for simple attributes // use the assemblies' cache for simple attributes
Add(assembly.MakeAttribute(type)); Add(module.MakeAttribute(type));
} }
/// <summary> /// <summary>
@ -68,7 +68,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// </summary> /// </summary>
public void Add(KnownAttribute type, KnownTypeCode argType, object argValue) public void Add(KnownAttribute type, KnownTypeCode argType, object argValue)
{ {
Add(type, ImmutableArray.Create(new CustomAttributeTypedArgument<IType>(assembly.Compilation.FindType(argType), argValue))); Add(type, ImmutableArray.Create(new CustomAttributeTypedArgument<IType>(module.Compilation.FindType(argType), argValue)));
} }
/// <summary> /// <summary>
@ -76,7 +76,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// </summary> /// </summary>
public void Add(KnownAttribute type, TopLevelTypeName argType, object argValue) public void Add(KnownAttribute type, TopLevelTypeName argType, object argValue)
{ {
Add(type, ImmutableArray.Create(new CustomAttributeTypedArgument<IType>(assembly.Compilation.FindType(argType), argValue))); Add(type, ImmutableArray.Create(new CustomAttributeTypedArgument<IType>(module.Compilation.FindType(argType), argValue)));
} }
/// <summary> /// <summary>
@ -84,7 +84,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// </summary> /// </summary>
public void Add(KnownAttribute type, ImmutableArray<CustomAttributeTypedArgument<IType>> fixedArguments) public void Add(KnownAttribute type, ImmutableArray<CustomAttributeTypedArgument<IType>> fixedArguments)
{ {
Add(new DefaultAttribute(assembly.GetAttributeType(type), fixedArguments, Add(new DefaultAttribute(module.GetAttributeType(type), fixedArguments,
ImmutableArray.Create<CustomAttributeNamedArgument<IType>>())); ImmutableArray.Create<CustomAttributeNamedArgument<IType>>()));
} }
@ -92,7 +92,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
internal void AddMarshalInfo(BlobHandle marshalInfo) internal void AddMarshalInfo(BlobHandle marshalInfo)
{ {
if (marshalInfo.IsNil) return; if (marshalInfo.IsNil) return;
var metadata = assembly.metadata; var metadata = module.metadata;
Add(ConvertMarshalInfo(metadata.GetBlobReader(marshalInfo))); Add(ConvertMarshalInfo(metadata.GetBlobReader(marshalInfo)));
} }
@ -100,8 +100,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IAttribute ConvertMarshalInfo(SRM.BlobReader marshalInfo) IAttribute ConvertMarshalInfo(SRM.BlobReader marshalInfo)
{ {
var b = new AttributeBuilder(assembly, KnownAttribute.MarshalAs); var b = new AttributeBuilder(module, KnownAttribute.MarshalAs);
IType unmanagedTypeType = assembly.Compilation.FindType(new TopLevelTypeName(InteropServices, nameof(UnmanagedType))); IType unmanagedTypeType = module.Compilation.FindType(new TopLevelTypeName(InteropServices, nameof(UnmanagedType)));
int type = marshalInfo.ReadByte(); int type = marshalInfo.ReadByte();
b.AddFixedArg(unmanagedTypeType, type); b.AddFixedArg(unmanagedTypeType, type);
@ -170,15 +170,15 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
#region Custom Attributes (ReadAttribute) #region Custom Attributes (ReadAttribute)
public void Add(CustomAttributeHandleCollection attributes) public void Add(CustomAttributeHandleCollection attributes)
{ {
var metadata = assembly.metadata; var metadata = module.metadata;
foreach (var handle in attributes) { foreach (var handle in attributes) {
var attribute = metadata.GetCustomAttribute(handle); var attribute = metadata.GetCustomAttribute(handle);
var ctor = assembly.ResolveMethod(attribute.Constructor); var ctor = module.ResolveMethod(attribute.Constructor);
var type = ctor.DeclaringType; var type = ctor.DeclaringType;
if (IgnoreAttribute(type)) { if (IgnoreAttribute(type)) {
continue; continue;
} }
Add(new CustomAttribute(assembly, ctor, handle)); Add(new CustomAttribute(module, ctor, handle));
} }
} }
@ -188,7 +188,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
return false; return false;
switch (attributeType.Namespace) { switch (attributeType.Namespace) {
case "System.Runtime.CompilerServices": case "System.Runtime.CompilerServices":
var options = assembly.TypeSystemOptions; var options = module.TypeSystemOptions;
switch (attributeType.Name) { switch (attributeType.Name) {
case "DynamicAttribute": case "DynamicAttribute":
return (options & TypeSystemOptions.Dynamic) != 0; return (options & TypeSystemOptions.Dynamic) != 0;
@ -212,7 +212,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
#region Security Attributes #region Security Attributes
public void AddSecurityAttributes(DeclarativeSecurityAttributeHandleCollection securityDeclarations) public void AddSecurityAttributes(DeclarativeSecurityAttributeHandleCollection securityDeclarations)
{ {
var metadata = assembly.metadata; var metadata = module.metadata;
foreach (var secDecl in securityDeclarations) { foreach (var secDecl in securityDeclarations) {
if (secDecl.IsNil) if (secDecl.IsNil)
continue; continue;
@ -222,9 +222,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public void AddSecurityAttributes(DeclarativeSecurityAttribute secDecl) 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<IType>(securityActionType, (int)secDecl.Action); var securityAction = new CustomAttributeTypedArgument<IType>(securityActionType, (int)secDecl.Action);
var metadata = assembly.metadata; var metadata = module.metadata;
var reader = metadata.GetBlobReader(secDecl.PermissionSet); var reader = metadata.GetBlobReader(secDecl.PermissionSet);
if (reader.ReadByte() == '.') { if (reader.ReadByte() == '.') {
// binary attribute // binary attribute
@ -242,7 +242,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
private void ReadXmlSecurityAttribute(ref SRM.BlobReader reader, CustomAttributeTypedArgument<IType> securityAction) private void ReadXmlSecurityAttribute(ref SRM.BlobReader reader, CustomAttributeTypedArgument<IType> securityAction)
{ {
string xml = reader.ReadUTF16(reader.RemainingBytes); string xml = reader.ReadUTF16(reader.RemainingBytes);
var b = new AttributeBuilder(assembly, KnownAttribute.PermissionSet); var b = new AttributeBuilder(module, KnownAttribute.PermissionSet);
b.AddFixedArg(securityAction); b.AddFixedArg(securityAction);
b.AddNamedArg("XML", KnownTypeCode.String, xml); b.AddNamedArg("XML", KnownTypeCode.String, xml);
} }
@ -250,13 +250,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
private IAttribute ReadBinarySecurityAttribute(ref SRM.BlobReader reader, CustomAttributeTypedArgument<IType> securityAction) private IAttribute ReadBinarySecurityAttribute(ref SRM.BlobReader reader, CustomAttributeTypedArgument<IType> securityAction)
{ {
string attributeTypeName = reader.ReadSerializedString(); string attributeTypeName = reader.ReadSerializedString();
IType attributeType = assembly.TypeProvider.GetTypeFromSerializedName(attributeTypeName); IType attributeType = module.TypeProvider.GetTypeFromSerializedName(attributeTypeName);
reader.ReadCompressedInteger(); // ?? reader.ReadCompressedInteger(); // ??
// The specification seems to be incorrect here, so I'm using the logic from Cecil instead. // The specification seems to be incorrect here, so I'm using the logic from Cecil instead.
int numNamed = reader.ReadCompressedInteger(); int numNamed = reader.ReadCompressedInteger();
var decoder = new Metadata.CustomAttributeDecoder<IType>(assembly.TypeProvider, assembly.metadata); var decoder = new Metadata.CustomAttributeDecoder<IType>(module.TypeProvider, module.metadata);
var namedArgs = decoder.DecodeNamedArguments(ref reader, numNamed); var namedArgs = decoder.DecodeNamedArguments(ref reader, numNamed);
return new DefaultAttribute( return new DefaultAttribute(
@ -282,14 +282,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
ImmutableArray<CustomAttributeTypedArgument<IType>>.Builder fixedArgs; ImmutableArray<CustomAttributeTypedArgument<IType>>.Builder fixedArgs;
ImmutableArray<CustomAttributeNamedArgument<IType>>.Builder namedArgs; ImmutableArray<CustomAttributeNamedArgument<IType>>.Builder namedArgs;
public AttributeBuilder(MetadataAssembly assembly, KnownAttribute attributeType) public AttributeBuilder(MetadataModule module, KnownAttribute attributeType)
: this(assembly, assembly.GetAttributeType(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.attributeType = attributeType;
this.fixedArgs = ImmutableArray.CreateBuilder<CustomAttributeTypedArgument<IType>>(); this.fixedArgs = ImmutableArray.CreateBuilder<CustomAttributeTypedArgument<IType>>();
this.namedArgs = ImmutableArray.CreateBuilder<CustomAttributeNamedArgument<IType>>(); this.namedArgs = ImmutableArray.CreateBuilder<CustomAttributeNamedArgument<IType>>();

12
ICSharpCode.Decompiler/TypeSystem/Implementation/CustomAttribute.cs

@ -34,7 +34,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// </summary> /// </summary>
sealed class CustomAttribute : IAttribute sealed class CustomAttribute : IAttribute
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly SRM.CustomAttributeHandle handle; readonly SRM.CustomAttributeHandle handle;
public IMethod Constructor { get; } public IMethod Constructor { get; }
@ -42,12 +42,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
SRM.CustomAttributeValue<IType> value; SRM.CustomAttributeValue<IType> value;
bool valueDecoded; 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(attrCtor != null);
Debug.Assert(!handle.IsNil); Debug.Assert(!handle.IsNil);
this.assembly = assembly; this.module = module;
this.Constructor = attrCtor; this.Constructor = attrCtor;
this.handle = handle; this.handle = handle;
} }
@ -72,9 +72,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{ {
lock (this) { lock (this) {
if (!valueDecoded) { if (!valueDecoded) {
var metadata = assembly.metadata; var metadata = module.metadata;
var attr = metadata.GetCustomAttribute(handle); var attr = metadata.GetCustomAttribute(handle);
value = attr.DecodeValue(assembly.TypeProvider); value = attr.DecodeValue(module.TypeProvider);
valueDecoded = true; valueDecoded = true;
} }
} }

16
ICSharpCode.Decompiler/TypeSystem/Implementation/DefaultAssemblyReference.cs

@ -24,9 +24,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// References an existing assembly by name. /// References an existing assembly by name.
/// </summary> /// </summary>
[Serializable] [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; readonly string shortName;
@ -39,12 +39,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
shortName = assemblyName; 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)) if (current != null && string.Equals(shortName, current.AssemblyName, StringComparison.OrdinalIgnoreCase))
return current; return current;
foreach (IAssembly asm in context.Compilation.Assemblies) { foreach (IModule asm in context.Compilation.Modules) {
if (string.Equals(shortName, asm.AssemblyName, StringComparison.OrdinalIgnoreCase)) if (string.Equals(shortName, asm.AssemblyName, StringComparison.OrdinalIgnoreCase))
return asm; return asm;
} }
@ -70,11 +70,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
} }
[Serializable] [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) if (asm == null)
throw new ArgumentException("A reference to the current assembly cannot be resolved in the compilation's global type resolve context."); throw new ArgumentException("A reference to the current assembly cannot be resolved in the compilation's global type resolve context.");
return asm; return asm;

2
ICSharpCode.Decompiler/TypeSystem/Implementation/FakeMember.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public IType DeclaringType { get; set; } public IType DeclaringType { get; set; }
IAssembly IEntity.ParentAssembly => DeclaringType?.GetDefinition()?.ParentAssembly; IModule IEntity.ParentModule => DeclaringType?.GetDefinition()?.ParentModule;
IEnumerable<IAttribute> IEntity.GetAttributes() => EmptyList<IAttribute>.Instance; IEnumerable<IAttribute> IEntity.GetAttributes() => EmptyList<IAttribute>.Instance;

32
ICSharpCode.Decompiler/TypeSystem/Implementation/GetClassTypeReference.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
[Serializable] [Serializable]
public sealed class GetClassTypeReference : ITypeReference, ISupportsInterning public sealed class GetClassTypeReference : ITypeReference, ISupportsInterning
{ {
readonly IAssemblyReference assembly; readonly IModuleReference module;
readonly FullTypeName fullTypeName; readonly FullTypeName fullTypeName;
readonly bool? isReferenceType; readonly bool? isReferenceType;
@ -34,14 +34,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// Creates a new GetClassTypeReference that searches a type definition. /// Creates a new GetClassTypeReference that searches a type definition.
/// </summary> /// </summary>
/// <param name="fullTypeName">The full name of the type.</param> /// <param name="fullTypeName">The full name of the type.</param>
/// <param name="assembly">A reference to the assembly containing this type. /// <param name="module">A reference to the module containing this type.
/// If this parameter is null, the GetClassTypeReference will search in all /// If this parameter is null, the GetClassTypeReference will search in all
/// assemblies belonging to the compilation. /// assemblies belonging to the compilation.
/// </param> /// </param>
public GetClassTypeReference(FullTypeName fullTypeName, IAssemblyReference assembly = null, bool? isReferenceType = null) public GetClassTypeReference(FullTypeName fullTypeName, IModuleReference module = null, bool? isReferenceType = null)
{ {
this.fullTypeName = fullTypeName; this.fullTypeName = fullTypeName;
this.assembly = assembly; this.module = module;
this.isReferenceType = isReferenceType; this.isReferenceType = isReferenceType;
} }
@ -60,14 +60,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// <summary> /// <summary>
/// Creates a new GetClassTypeReference that searches a top-level type in the specified assembly. /// Creates a new GetClassTypeReference that searches a top-level type in the specified assembly.
/// </summary> /// </summary>
/// <param name="assembly">A reference to the assembly containing this type. /// <param name="module">A reference to the assembly containing this type.
/// If this parameter is null, the GetClassTypeReference will search in all assemblies belonging to the ICompilation.</param> /// If this parameter is null, the GetClassTypeReference will search in all assemblies belonging to the ICompilation.</param>
/// <param name="namespaceName">The namespace name containing the type, e.g. "System.Collections.Generic".</param> /// <param name="namespaceName">The namespace name containing the type, e.g. "System.Collections.Generic".</param>
/// <param name="name">The name of the type, e.g. "List".</param> /// <param name="name">The name of the type, e.g. "List".</param>
/// <param name="typeParameterCount">The number of type parameters, (e.g. 1 for List&lt;T&gt;).</param> /// <param name="typeParameterCount">The number of type parameters, (e.g. 1 for List&lt;T&gt;).</param>
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.fullTypeName = new TopLevelTypeName(namespaceName, name, typeParameterCount);
this.isReferenceType = isReferenceType; this.isReferenceType = isReferenceType;
} }
@ -77,7 +77,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// This property returns null if the GetClassTypeReference is searching in all assemblies /// This property returns null if the GetClassTypeReference is searching in all assemblies
/// of the compilation. /// of the compilation.
/// </summary> /// </summary>
public IAssemblyReference Assembly { get { return assembly; } } public IModuleReference Module { get { return module; } }
/// <summary> /// <summary>
/// Gets the full name of the type this reference is searching for. /// 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) IType ResolveInAllAssemblies(ITypeResolveContext context)
{ {
var compilation = context.Compilation; var compilation = context.Compilation;
foreach (var asm in compilation.Assemblies) { foreach (var asm in compilation.Modules) {
IType type = asm.GetTypeDefinition(fullTypeName); IType type = asm.GetTypeDefinition(fullTypeName);
if (type != null) if (type != null)
return type; return type;
@ -101,10 +101,10 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
throw new ArgumentNullException("context"); throw new ArgumentNullException("context");
IType type = null; IType type = null;
if (assembly == null) { if (module == null) {
// No assembly specified: look in all assemblies, but prefer the current assembly // No assembly specified: look in all assemblies, but prefer the current assembly
if (context.CurrentAssembly != null) { if (context.CurrentModule != null) {
type = context.CurrentAssembly.GetTypeDefinition(fullTypeName); type = context.CurrentModule.GetTypeDefinition(fullTypeName);
} }
if (type == null) { if (type == null) {
type = ResolveInAllAssemblies(context); 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. // 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 - // (the non-loaded assembly might be a facade containing type forwarders -
// for example, when referencing a portable library from a non-portable project) // 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) { if (asm != null) {
type = asm.GetTypeDefinition(fullTypeName); type = asm.GetTypeDefinition(fullTypeName);
} else { } else {
@ -126,20 +126,20 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public override string ToString() public override string ToString()
{ {
return fullTypeName.ToString() + (assembly != null ? ", " + assembly.ToString() : null); return fullTypeName.ToString() + (module != null ? ", " + module.ToString() : null);
} }
int ISupportsInterning.GetHashCodeForInterning() int ISupportsInterning.GetHashCodeForInterning()
{ {
unchecked { unchecked {
return 33 * assembly.GetHashCode() + fullTypeName.GetHashCode(); return 33 * module.GetHashCode() + fullTypeName.GetHashCode();
} }
} }
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other) bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
{ {
GetClassTypeReference o = other as GetClassTypeReference; 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;
} }
} }
} }

2
ICSharpCode.Decompiler/TypeSystem/Implementation/KnownTypeCache.cs

@ -48,7 +48,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
if (typeRef == null) if (typeRef == null)
return SpecialType.UnknownType; return SpecialType.UnknownType;
var typeName = new TopLevelTypeName(typeRef.Namespace, typeRef.Name, typeRef.TypeParameterCount); 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); var typeDef = asm.GetTypeDefinition(typeName);
if (typeDef != null) if (typeDef != null)
return typeDef; return typeDef;

4
ICSharpCode.Decompiler/TypeSystem/Implementation/MergedNamespace.cs

@ -99,8 +99,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
get { return compilation; } get { return compilation; }
} }
public IEnumerable<IAssembly> ContributingAssemblies { public IEnumerable<IModule> ContributingModules {
get { return namespaces.SelectMany(ns => ns.ContributingAssemblies); } get { return namespaces.SelectMany(ns => ns.ContributingModules); }
} }
public IEnumerable<INamespace> ChildNamespaces { public IEnumerable<INamespace> ChildNamespaces {

34
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataEvent.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{ {
sealed class MetadataEvent : IEvent sealed class MetadataEvent : IEvent
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly EventDefinitionHandle handle; readonly EventDefinitionHandle handle;
readonly EventAccessors accessors; readonly EventAccessors accessors;
readonly string name; readonly string name;
@ -40,14 +40,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
// lazy-loaded: // lazy-loaded:
IType returnType; 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); Debug.Assert(!handle.IsNil);
this.assembly = assembly; this.module = module;
this.handle = handle; this.handle = handle;
var metadata = assembly.metadata; var metadata = module.metadata;
var ev = metadata.GetEventDefinition(handle); var ev = metadata.GetEventDefinition(handle);
accessors = ev.GetAccessors(); accessors = ev.GetAccessors();
name = metadata.GetString(ev.Name); name = metadata.GetString(ev.Name);
@ -66,10 +66,10 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public bool CanAdd => !accessors.Adder.IsNil; public bool CanAdd => !accessors.Adder.IsNil;
public bool CanRemove => !accessors.Remover.IsNil; public bool CanRemove => !accessors.Remover.IsNil;
public bool CanInvoke => !accessors.Raiser.IsNil; public bool CanInvoke => !accessors.Raiser.IsNil;
public IMethod AddAccessor => assembly.GetDefinition(accessors.Adder); public IMethod AddAccessor => module.GetDefinition(accessors.Adder);
public IMethod RemoveAccessor => assembly.GetDefinition(accessors.Remover); public IMethod RemoveAccessor => module.GetDefinition(accessors.Remover);
public IMethod InvokeAccessor => assembly.GetDefinition(accessors.Raiser); public IMethod InvokeAccessor => module.GetDefinition(accessors.Raiser);
IMethod AnyAccessor => assembly.GetDefinition(accessors.GetAny()); IMethod AnyAccessor => module.GetDefinition(accessors.GetAny());
#region Signature (ReturnType + Parameters) #region Signature (ReturnType + Parameters)
public IType ReturnType { public IType ReturnType {
@ -77,10 +77,10 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
var returnType = LazyInit.VolatileRead(ref this.returnType); var returnType = LazyInit.VolatileRead(ref this.returnType);
if (returnType != null) if (returnType != null)
return returnType; return returnType;
var metadata = assembly.metadata; var metadata = module.metadata;
var ev = metadata.GetEventDefinition(handle); var ev = metadata.GetEventDefinition(handle);
var context = new GenericContext(DeclaringTypeDefinition?.TypeParameters); 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); return LazyInit.GetOrSet(ref this.returnType, returnType);
} }
} }
@ -104,8 +104,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
#region Attributes #region Attributes
public IEnumerable<IAttribute> GetAttributes() public IEnumerable<IAttribute> GetAttributes()
{ {
var b = new AttributeListBuilder(assembly); var b = new AttributeListBuilder(module);
var metadata = assembly.metadata; var metadata = module.metadata;
var eventDef = metadata.GetEventDefinition(handle); var eventDef = metadata.GetEventDefinition(handle);
b.Add(eventDef.GetCustomAttributes()); b.Add(eventDef.GetCustomAttributes());
return b.Build(); return b.Build();
@ -120,8 +120,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public bool IsOverride => AnyAccessor?.IsOverride ?? false; public bool IsOverride => AnyAccessor?.IsOverride ?? false;
public bool IsOverridable => AnyAccessor?.IsOverridable ?? false; public bool IsOverridable => AnyAccessor?.IsOverridable ?? false;
public IAssembly ParentAssembly => assembly; public IModule ParentModule => module;
public ICompilation Compilation => assembly.Compilation; public ICompilation Compilation => module.Compilation;
public string FullName => $"{DeclaringType?.FullName}.{Name}"; public string FullName => $"{DeclaringType?.FullName}.{Name}";
public string ReflectionName => $"{DeclaringType?.ReflectionName}.{Name}"; public string ReflectionName => $"{DeclaringType?.ReflectionName}.{Name}";
@ -130,14 +130,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is MetadataEvent ev) { 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; return false;
} }
public override int GetHashCode() 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) bool IMember.Equals(IMember obj, TypeVisitor typeNormalization)

40
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataField.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// </summary> /// </summary>
sealed class MetadataField : IField sealed class MetadataField : IField
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly FieldDefinitionHandle handle; readonly FieldDefinitionHandle handle;
readonly FieldAttributes attributes; readonly FieldAttributes attributes;
@ -44,13 +44,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
bool isVolatile; // initialized together with this.type bool isVolatile; // initialized together with this.type
byte decimalConstant; // 0=no, 1=yes, 2=unknown 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); Debug.Assert(!handle.IsNil);
this.assembly = assembly; this.module = module;
this.handle = handle; this.handle = handle;
var def = assembly.metadata.GetFieldDefinition(handle); var def = module.metadata.GetFieldDefinition(handle);
this.attributes = def.Attributes; this.attributes = def.Attributes;
if ((attributes & (FieldAttributes.Static | FieldAttributes.InitOnly)) == (FieldAttributes.Static | FieldAttributes.InitOnly)) { if ((attributes & (FieldAttributes.Static | FieldAttributes.InitOnly)) == (FieldAttributes.Static | FieldAttributes.InitOnly)) {
decimalConstant = 2; // may be decimal constant decimalConstant = 2; // may be decimal constant
@ -69,7 +69,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
string name = LazyInit.VolatileRead(ref this.name); string name = LazyInit.VolatileRead(ref this.name);
if (name != null) if (name != null)
return name; return name;
var metadata = assembly.metadata; var metadata = module.metadata;
var fieldDef = metadata.GetFieldDefinition(handle); var fieldDef = metadata.GetFieldDefinition(handle);
return LazyInit.GetOrSet(ref this.name, metadata.GetString(fieldDef.Name)); return LazyInit.GetOrSet(ref this.name, metadata.GetString(fieldDef.Name));
} }
@ -116,21 +116,21 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
if (declType != null) { if (declType != null) {
return declType; return declType;
} else { } else {
var def = assembly.metadata.GetFieldDefinition(handle); var def = module.metadata.GetFieldDefinition(handle);
return LazyInit.GetOrSet(ref this.declaringType, return LazyInit.GetOrSet(ref this.declaringType,
assembly.GetDefinition(def.GetDeclaringType())); module.GetDefinition(def.GetDeclaringType()));
} }
} }
} }
public IType DeclaringType => DeclaringTypeDefinition; public IType DeclaringType => DeclaringTypeDefinition;
public IAssembly ParentAssembly => assembly; public IModule ParentModule => module;
public ICompilation Compilation => assembly.Compilation; public ICompilation Compilation => module.Compilation;
public IEnumerable<IAttribute> GetAttributes() public IEnumerable<IAttribute> GetAttributes()
{ {
var b = new AttributeListBuilder(assembly); var b = new AttributeListBuilder(module);
var metadata = assembly.metadata; var metadata = module.metadata;
var fieldDef = metadata.GetFieldDefinition(handle); var fieldDef = metadata.GetFieldDefinition(handle);
// FieldOffsetAttribute // FieldOffsetAttribute
@ -175,15 +175,15 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
private IType DecodeTypeAndVolatileFlag() private IType DecodeTypeAndVolatileFlag()
{ {
var metadata = assembly.metadata; var metadata = module.metadata;
var fieldDef = metadata.GetFieldDefinition(handle); 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") { if (ty is ModifiedType mod && mod.Modifier.Name == "IsVolatile" && mod.Modifier.Namespace == "System.Runtime.CompilerServices") {
Volatile.Write(ref this.isVolatile, true); Volatile.Write(ref this.isVolatile, true);
ty = mod.ElementType; ty = mod.ElementType;
} }
ty = ApplyAttributeTypeVisitor.ApplyAttributesToType(ty, Compilation, ty = ApplyAttributeTypeVisitor.ApplyAttributesToType(ty, Compilation,
fieldDef.GetCustomAttributes(), metadata, assembly.TypeSystemOptions); fieldDef.GetCustomAttributes(), metadata, module.TypeSystemOptions);
return LazyInit.GetOrSet(ref this.type, ty); return LazyInit.GetOrSet(ref this.type, ty);
} }
@ -192,7 +192,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
bool IsDecimalConstant { bool IsDecimalConstant {
get { get {
if (decimalConstant == 2) { if (decimalConstant == 2) {
var metadata = assembly.metadata; var metadata = module.metadata;
var fieldDef = metadata.GetFieldDefinition(handle); var fieldDef = metadata.GetFieldDefinition(handle);
if (fieldDef.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.DecimalConstant)) if (fieldDef.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.DecimalConstant))
decimalConstant = 1; decimalConstant = 1;
@ -208,7 +208,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
object val = LazyInit.VolatileRead(ref this.constantValue); object val = LazyInit.VolatileRead(ref this.constantValue);
if (val != null) if (val != null)
return val; return val;
var metadata = assembly.metadata; var metadata = module.metadata;
var fieldDef = metadata.GetFieldDefinition(handle); var fieldDef = metadata.GetFieldDefinition(handle);
if (IsDecimalConstant) { if (IsDecimalConstant) {
foreach (var attrHandle in fieldDef.GetCustomAttributes()) { foreach (var attrHandle in fieldDef.GetCustomAttributes()) {
@ -231,7 +231,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
decimal? TryDecodeDecimalConstantAttribute(System.Reflection.Metadata.CustomAttribute attribute) decimal? TryDecodeDecimalConstantAttribute(System.Reflection.Metadata.CustomAttribute attribute)
{ {
var attrValue = attribute.DecodeValue(assembly.TypeProvider); var attrValue = attribute.DecodeValue(module.TypeProvider);
if (attrValue.FixedArguments.Length != 5) if (attrValue.FixedArguments.Length != 5)
return null; 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) // 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) public override bool Equals(object obj)
{ {
if (obj is MetadataField f) { 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; return false;
} }
public override int GetHashCode() 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) bool IMember.Equals(IMember obj, TypeVisitor typeNormalization)

68
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataMethod.cs

@ -32,7 +32,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{ {
sealed class MetadataMethod : IMethod sealed class MetadataMethod : IMethod
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly MethodDefinitionHandle handle; readonly MethodDefinitionHandle handle;
// eagerly loaded fields: // eagerly loaded fields:
@ -48,18 +48,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IParameter[] parameters; IParameter[] parameters;
IType returnType; 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); Debug.Assert(!handle.IsNil);
this.assembly = assembly; this.module = module;
this.handle = handle; this.handle = handle;
var metadata = assembly.metadata; var metadata = module.metadata;
var def = metadata.GetMethodDefinition(handle); var def = metadata.GetMethodDefinition(handle);
this.attributes = def.Attributes; this.attributes = def.Attributes;
this.symbolKind = SymbolKind.Method; this.symbolKind = SymbolKind.Method;
var (accessorOwner, semanticsAttribute) = assembly.PEFile.MethodSemanticsLookup.GetSemantics(handle); var (accessorOwner, semanticsAttribute) = module.PEFile.MethodSemanticsLookup.GetSemantics(handle);
if (semanticsAttribute != 0) { if (semanticsAttribute != 0) {
this.symbolKind = SymbolKind.Accessor; this.symbolKind = SymbolKind.Accessor;
this.accessorOwner = accessorOwner; this.accessorOwner = accessorOwner;
@ -70,9 +70,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
else if (name.StartsWith("op_", StringComparison.Ordinal)) else if (name.StartsWith("op_", StringComparison.Ordinal))
this.symbolKind = SymbolKind.Operator; 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 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); && def.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.Extension);
} }
@ -88,7 +88,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
string name = LazyInit.VolatileRead(ref this.name); string name = LazyInit.VolatileRead(ref this.name);
if (name != null) if (name != null)
return name; return name;
var metadata = assembly.metadata; var metadata = module.metadata;
var methodDef = metadata.GetMethodDefinition(handle); var methodDef = metadata.GetMethodDefinition(handle);
return LazyInit.GetOrSet(ref this.name, metadata.GetString(methodDef.Name)); 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 IsOperator => symbolKind == SymbolKind.Operator;
public bool IsAccessor => symbolKind == SymbolKind.Accessor; 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 { public IMember AccessorOwner {
@ -111,9 +111,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
if (accessorOwner.IsNil) if (accessorOwner.IsNil)
return null; return null;
if (accessorOwner.Kind == HandleKind.PropertyDefinition) if (accessorOwner.Kind == HandleKind.PropertyDefinition)
return assembly.GetDefinition((PropertyDefinitionHandle)accessorOwner); return module.GetDefinition((PropertyDefinitionHandle)accessorOwner);
else if (accessorOwner.Kind == HandleKind.EventDefinition) else if (accessorOwner.Kind == HandleKind.EventDefinition)
return assembly.GetDefinition((EventDefinitionHandle)accessorOwner); return module.GetDefinition((EventDefinitionHandle)accessorOwner);
else else
return null; return null;
} }
@ -142,17 +142,17 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
private void DecodeSignature() private void DecodeSignature()
{ {
var methodDef = assembly.metadata.GetMethodDefinition(handle); var methodDef = module.metadata.GetMethodDefinition(handle);
var genericContext = new GenericContext(DeclaringType.TypeParameters, this.TypeParameters); var genericContext = new GenericContext(DeclaringType.TypeParameters, this.TypeParameters);
var signature = methodDef.DecodeSignature(assembly.TypeProvider, genericContext); var signature = methodDef.DecodeSignature(module.TypeProvider, genericContext);
var (returnType, parameters) = DecodeSignature(assembly, this, signature, methodDef.GetParameters()); var (returnType, parameters) = DecodeSignature(module, this, signature, methodDef.GetParameters());
LazyInit.GetOrSet(ref this.returnType, returnType); LazyInit.GetOrSet(ref this.returnType, returnType);
LazyInit.GetOrSet(ref this.parameters, parameters); LazyInit.GetOrSet(ref this.parameters, parameters);
} }
internal static (IType, IParameter[]) DecodeSignature(MetadataAssembly assembly, IParameterizedMember owner, MethodSignature<IType> signature, ParameterHandleCollection? parameterHandles) internal static (IType, IParameter[]) DecodeSignature(MetadataModule module, IParameterizedMember owner, MethodSignature<IType> signature, ParameterHandleCollection? parameterHandles)
{ {
var metadata = assembly.metadata; var metadata = module.metadata;
int i = 0; int i = 0;
CustomAttributeHandleCollection? returnTypeAttributes = null; CustomAttributeHandleCollection? returnTypeAttributes = null;
IParameter[] parameters = new IParameter[signature.RequiredParameterCount IParameter[] parameters = new IParameter[signature.RequiredParameterCount
@ -166,16 +166,16 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
} else if (par.SequenceNumber > 0 && i < signature.RequiredParameterCount) { } else if (par.SequenceNumber > 0 && i < signature.RequiredParameterCount) {
Debug.Assert(par.SequenceNumber - 1 == i); Debug.Assert(par.SequenceNumber - 1 == i);
var parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( var parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType(
signature.ParameterTypes[i], assembly.Compilation, signature.ParameterTypes[i], module.Compilation,
par.GetCustomAttributes(), metadata, assembly.TypeSystemOptions); par.GetCustomAttributes(), metadata, module.TypeSystemOptions);
parameters[i] = new MetadataParameter(assembly, owner, parameterType, parameterHandle); parameters[i] = new MetadataParameter(module, owner, parameterType, parameterHandle);
i++; i++;
} }
} }
} }
while (i < signature.RequiredParameterCount) { while (i < signature.RequiredParameterCount) {
var parameterType = ApplyAttributeTypeVisitor.ApplyAttributesToType( 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, parameters[i] = new DefaultParameter(parameterType, name: string.Empty, owner,
isRef: parameterType.Kind == TypeKind.ByReference); isRef: parameterType.Kind == TypeKind.ByReference);
i++; i++;
@ -186,7 +186,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
} }
Debug.Assert(i == parameters.Length); Debug.Assert(i == parameters.Length);
var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType, var returnType = ApplyAttributeTypeVisitor.ApplyAttributesToType(signature.ReturnType,
assembly.Compilation, returnTypeAttributes, metadata, assembly.TypeSystemOptions); module.Compilation, returnTypeAttributes, metadata, module.TypeSystemOptions);
return (returnType, parameters); return (returnType, parameters);
} }
#endregion #endregion
@ -217,38 +217,38 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
if (declType != null) { if (declType != null) {
return declType; return declType;
} else { } else {
var def = assembly.metadata.GetMethodDefinition(handle); var def = module.metadata.GetMethodDefinition(handle);
return LazyInit.GetOrSet(ref this.declaringType, return LazyInit.GetOrSet(ref this.declaringType,
assembly.GetDefinition(def.GetDeclaringType())); module.GetDefinition(def.GetDeclaringType()));
} }
} }
} }
public IType DeclaringType => DeclaringTypeDefinition; public IType DeclaringType => DeclaringTypeDefinition;
public IAssembly ParentAssembly => assembly; public IModule ParentModule => module;
public ICompilation Compilation => assembly.Compilation; public ICompilation Compilation => module.Compilation;
#region Attributes #region Attributes
IType FindInteropType(string name) IType FindInteropType(string name)
{ {
return assembly.Compilation.FindType(new TopLevelTypeName( return module.Compilation.FindType(new TopLevelTypeName(
"System.Runtime.InteropServices", name, 0 "System.Runtime.InteropServices", name, 0
)); ));
} }
public IEnumerable<IAttribute> GetAttributes() public IEnumerable<IAttribute> GetAttributes()
{ {
var b = new AttributeListBuilder(assembly); var b = new AttributeListBuilder(module);
var metadata = assembly.metadata; var metadata = module.metadata;
var def = metadata.GetMethodDefinition(handle); var def = metadata.GetMethodDefinition(handle);
MethodImplAttributes implAttributes = def.ImplAttributes & ~MethodImplAttributes.CodeTypeMask; MethodImplAttributes implAttributes = def.ImplAttributes & ~MethodImplAttributes.CodeTypeMask;
#region DllImportAttribute #region DllImportAttribute
var info = def.GetImport(); var info = def.GetImport();
if ((attributes & MethodAttributes.PinvokeImpl) == MethodAttributes.PinvokeImpl && !info.Module.IsNil) { 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, dllImport.AddFixedArg(KnownTypeCode.String,
metadata.GetString(metadata.GetModuleReference(info.Module).Name)); metadata.GetString(metadata.GetModuleReference(info.Module).Name));
@ -356,8 +356,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
#region Return type attributes #region Return type attributes
public IEnumerable<IAttribute> GetReturnTypeAttributes() public IEnumerable<IAttribute> GetReturnTypeAttributes()
{ {
var b = new AttributeListBuilder(assembly); var b = new AttributeListBuilder(module);
var metadata = assembly.metadata; var metadata = module.metadata;
var methodDefinition = metadata.GetMethodDefinition(handle); var methodDefinition = metadata.GetMethodDefinition(handle);
var parameters = methodDefinition.GetParameters(); var parameters = methodDefinition.GetParameters();
if (parameters.Count > 0) { if (parameters.Count > 0) {
@ -409,14 +409,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is MetadataMethod m) { 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; return false;
} }
public override int GetHashCode() 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) bool IMember.Equals(IMember obj, TypeVisitor typeNormalization)

24
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataNamespace.cs

@ -26,22 +26,22 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{ {
sealed class MetadataNamespace : INamespace sealed class MetadataNamespace : INamespace
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly NamespaceDefinition ns; readonly NamespaceDefinition ns;
public INamespace ParentNamespace { get; } public INamespace ParentNamespace { get; }
public string FullName { get; } public string FullName { get; }
public string Name { 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); Debug.Assert(fullName != null);
this.assembly = assembly; this.module = module;
this.ParentNamespace = parent; this.ParentNamespace = parent;
this.ns = ns; this.ns = ns;
this.FullName = fullName; this.FullName = fullName;
this.Name = assembly.GetString(ns.Name); this.Name = module.GetString(ns.Name);
} }
string INamespace.ExternAlias => string.Empty; string INamespace.ExternAlias => string.Empty;
@ -58,9 +58,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
children = new INamespace[nsDefs.Length]; children = new INamespace[nsDefs.Length];
for (int i = 0; i < children.Length; i++) { for (int i = 0; i < children.Length; i++) {
var nsHandle = nsDefs[i]; var nsHandle = nsDefs[i];
string fullName = assembly.metadata.GetString(nsHandle); string fullName = module.metadata.GetString(nsHandle);
children[i] = new MetadataNamespace(assembly, this, fullName, children[i] = new MetadataNamespace(module, this, fullName,
assembly.metadata.GetNamespaceDefinition(nsHandle)); module.metadata.GetNamespaceDefinition(nsHandle));
} }
return LazyInit.GetOrSet(ref childNamespaces, children); return LazyInit.GetOrSet(ref childNamespaces, children);
} }
@ -69,18 +69,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IEnumerable<ITypeDefinition> INamespace.Types { IEnumerable<ITypeDefinition> INamespace.Types {
get { get {
foreach (var typeHandle in ns.TypeDefinitions) { foreach (var typeHandle in ns.TypeDefinitions) {
var def = assembly.GetDefinition(typeHandle); var def = module.GetDefinition(typeHandle);
if (def != null) if (def != null)
yield return def; yield return def;
} }
} }
} }
IEnumerable<IAssembly> INamespace.ContributingAssemblies => new[] { assembly }; IEnumerable<IModule> INamespace.ContributingModules => new[] { module };
SymbolKind ISymbol.SymbolKind => SymbolKind.Namespace; SymbolKind ISymbol.SymbolKind => SymbolKind.Namespace;
ICompilation ICompilationProvider.Compilation => assembly.Compilation; ICompilation ICompilationProvider.Compilation => module.Compilation;
INamespace INamespace.GetChildNamespace(string name) INamespace INamespace.GetChildNamespace(string name)
{ {
@ -93,7 +93,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
ITypeDefinition INamespace.GetTypeDefinition(string name, int typeParameterCount) ITypeDefinition INamespace.GetTypeDefinition(string name, int typeParameterCount)
{ {
return assembly.GetTypeDefinition(FullName, name, typeParameterCount); return module.GetTypeDefinition(FullName, name, typeParameterCount);
} }
} }
} }

18
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataParameter.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{ {
sealed class MetadataParameter : IParameter sealed class MetadataParameter : IParameter
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly ParameterHandle handle; readonly ParameterHandle handle;
readonly ParameterAttributes attributes; readonly ParameterAttributes attributes;
@ -38,14 +38,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
// lazy-loaded: // lazy-loaded:
string name; 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.Owner = owner;
this.Type = type; this.Type = type;
this.handle = handle; this.handle = handle;
var param = assembly.metadata.GetParameter(handle); var param = module.metadata.GetParameter(handle);
this.attributes = param.Attributes; this.attributes = param.Attributes;
} }
@ -54,8 +54,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
#region Attributes #region Attributes
public IEnumerable<IAttribute> GetAttributes() public IEnumerable<IAttribute> GetAttributes()
{ {
var b = new AttributeListBuilder(assembly); var b = new AttributeListBuilder(module);
var metadata = assembly.metadata; var metadata = module.metadata;
var parameter = metadata.GetParameter(handle); var parameter = metadata.GetParameter(handle);
if (!IsOut) { if (!IsOut) {
@ -80,7 +80,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
get { get {
if (Type.Kind != TypeKind.Array) if (Type.Kind != TypeKind.Array)
return false; return false;
var metadata = assembly.metadata; var metadata = module.metadata;
var propertyDef = metadata.GetParameter(handle); var propertyDef = metadata.GetParameter(handle);
return propertyDef.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.ParamArray); return propertyDef.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.ParamArray);
} }
@ -91,7 +91,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
string name = LazyInit.VolatileRead(ref this.name); string name = LazyInit.VolatileRead(ref this.name);
if (name != null) if (name != null)
return name; return name;
var metadata = assembly.metadata; var metadata = module.metadata;
var propertyDef = metadata.GetParameter(handle); var propertyDef = metadata.GetParameter(handle);
return LazyInit.GetOrSet(ref this.name, metadata.GetString(propertyDef.Name)); return LazyInit.GetOrSet(ref this.name, metadata.GetString(propertyDef.Name));
} }
@ -101,7 +101,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public object ConstantValue { public object ConstantValue {
get { get {
var metadata = assembly.metadata; var metadata = module.metadata;
var propertyDef = metadata.GetParameter(handle); var propertyDef = metadata.GetParameter(handle);
var constantHandle = propertyDef.GetDefaultValue(); var constantHandle = propertyDef.GetDefaultValue();
if (constantHandle.IsNil) if (constantHandle.IsNil)

41
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 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Reflection.Metadata; using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335; using System.Reflection.Metadata.Ecma335;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using ICSharpCode.Decompiler.Semantics;
using ICSharpCode.Decompiler.Util; using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.Decompiler.TypeSystem.Implementation namespace ICSharpCode.Decompiler.TypeSystem.Implementation
@ -34,7 +29,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{ {
const Accessibility InvalidAccessibility = (Accessibility)0xff; const Accessibility InvalidAccessibility = (Accessibility)0xff;
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly PropertyDefinitionHandle propertyHandle; readonly PropertyDefinitionHandle propertyHandle;
readonly IMethod getter; readonly IMethod getter;
readonly IMethod setter; readonly IMethod setter;
@ -46,18 +41,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IParameter[] parameters; IParameter[] parameters;
IType returnType; 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); Debug.Assert(!handle.IsNil);
this.assembly = assembly; this.module = module;
this.propertyHandle = handle; this.propertyHandle = handle;
var metadata = assembly.metadata; var metadata = module.metadata;
var prop = metadata.GetPropertyDefinition(handle); var prop = metadata.GetPropertyDefinition(handle);
var accessors = prop.GetAccessors(); var accessors = prop.GetAccessors();
getter = assembly.GetDefinition(accessors.Getter); getter = module.GetDefinition(accessors.Getter);
setter = assembly.GetDefinition(accessors.Setter); setter = module.GetDefinition(accessors.Setter);
name = metadata.GetString(prop.Name); name = metadata.GetString(prop.Name);
if (name == (DeclaringTypeDefinition as MetadataTypeDefinition)?.DefaultMemberName) { if (name == (DeclaringTypeDefinition as MetadataTypeDefinition)?.DefaultMemberName) {
symbolKind = SymbolKind.Indexer; symbolKind = SymbolKind.Indexer;
@ -111,18 +106,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
private void DecodeSignature() private void DecodeSignature()
{ {
var propertyDef = assembly.metadata.GetPropertyDefinition(propertyHandle); var propertyDef = module.metadata.GetPropertyDefinition(propertyHandle);
var genericContext = new GenericContext(DeclaringType.TypeParameters); var genericContext = new GenericContext(DeclaringType.TypeParameters);
var signature = propertyDef.DecodeSignature(assembly.TypeProvider, genericContext); var signature = propertyDef.DecodeSignature(module.TypeProvider, genericContext);
var accessors = propertyDef.GetAccessors(); var accessors = propertyDef.GetAccessors();
ParameterHandleCollection? parameterHandles; ParameterHandleCollection? parameterHandles;
if (!accessors.Getter.IsNil) if (!accessors.Getter.IsNil)
parameterHandles = assembly.metadata.GetMethodDefinition(accessors.Getter).GetParameters(); parameterHandles = module.metadata.GetMethodDefinition(accessors.Getter).GetParameters();
else if (!accessors.Setter.IsNil) else if (!accessors.Setter.IsNil)
parameterHandles = assembly.metadata.GetMethodDefinition(accessors.Setter).GetParameters(); parameterHandles = module.metadata.GetMethodDefinition(accessors.Setter).GetParameters();
else else
parameterHandles = null; 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.returnType, returnType);
LazyInit.GetOrSet(ref this.parameters, parameters); LazyInit.GetOrSet(ref this.parameters, parameters);
} }
@ -146,8 +141,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
#region Attributes #region Attributes
public IEnumerable<IAttribute> GetAttributes() public IEnumerable<IAttribute> GetAttributes()
{ {
var b = new AttributeListBuilder(assembly); var b = new AttributeListBuilder(module);
var metadata = assembly.metadata; var metadata = module.metadata;
var propertyDef = metadata.GetPropertyDefinition(propertyHandle); var propertyDef = metadata.GetPropertyDefinition(propertyHandle);
if (IsIndexer && Name != "Item" && !IsExplicitInterfaceImplementation) { if (IsIndexer && Name != "Item" && !IsExplicitInterfaceImplementation) {
b.Add(KnownAttribute.IndexerName, KnownTypeCode.String, Name); b.Add(KnownAttribute.IndexerName, KnownTypeCode.String, Name);
@ -213,8 +208,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public bool IsOverride => AnyAccessor?.IsOverride ?? false; public bool IsOverride => AnyAccessor?.IsOverride ?? false;
public bool IsOverridable => AnyAccessor?.IsOverridable ?? false; public bool IsOverridable => AnyAccessor?.IsOverridable ?? false;
public IAssembly ParentAssembly => assembly; public IModule ParentModule => module;
public ICompilation Compilation => assembly.Compilation; public ICompilation Compilation => module.Compilation;
public string FullName => $"{DeclaringType?.FullName}.{Name}"; public string FullName => $"{DeclaringType?.FullName}.{Name}";
public string ReflectionName => $"{DeclaringType?.ReflectionName}.{Name}"; public string ReflectionName => $"{DeclaringType?.ReflectionName}.{Name}";
@ -223,14 +218,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is MetadataProperty p) { 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; return false;
} }
public override int GetHashCode() 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) bool IMember.Equals(IMember obj, TypeVisitor typeNormalization)

80
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeDefinition.cs

@ -37,7 +37,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// </summary> /// </summary>
sealed class MetadataTypeDefinition : ITypeDefinition sealed class MetadataTypeDefinition : ITypeDefinition
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly TypeDefinitionHandle handle; readonly TypeDefinitionHandle handle;
// eagerly loaded: // eagerly loaded:
@ -59,25 +59,25 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
List<IType> directBaseTypes; List<IType> directBaseTypes;
string defaultMemberName; 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); Debug.Assert(!handle.IsNil);
this.assembly = assembly; this.module = module;
this.handle = handle; this.handle = handle;
var metadata = assembly.metadata; var metadata = module.metadata;
var td = metadata.GetTypeDefinition(handle); var td = metadata.GetTypeDefinition(handle);
this.attributes = td.Attributes; this.attributes = td.Attributes;
this.fullTypeName = td.GetFullTypeName(metadata); this.fullTypeName = td.GetFullTypeName(metadata);
// Find DeclaringType + KnownTypeCode: // Find DeclaringType + KnownTypeCode:
if (fullTypeName.IsNested) { if (fullTypeName.IsNested) {
this.DeclaringTypeDefinition = assembly.GetDefinition(td.GetDeclaringType()); this.DeclaringTypeDefinition = module.GetDefinition(td.GetDeclaringType());
// Create type parameters: // Create type parameters:
this.TypeParameters = MetadataTypeParameter.Create(assembly, this.DeclaringTypeDefinition, this, td.GetGenericParameters()); this.TypeParameters = MetadataTypeParameter.Create(module, this.DeclaringTypeDefinition, this, td.GetGenericParameters());
} else { } else {
// Create type parameters: // Create type parameters:
this.TypeParameters = MetadataTypeParameter.Create(assembly, this, td.GetGenericParameters()); this.TypeParameters = MetadataTypeParameter.Create(module, this, td.GetGenericParameters());
var topLevelTypeName = fullTypeName.TopLevelTypeName; var topLevelTypeName = fullTypeName.TopLevelTypeName;
for (int i = 0; i < KnownTypeReference.KnownTypeCodeCount; i++) { for (int i = 0; i < KnownTypeReference.KnownTypeCodeCount; i++) {
@ -93,7 +93,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
this.Kind = TypeKind.Interface; this.Kind = TypeKind.Interface;
} else if (td.IsEnum(metadata, out var underlyingType)) { } else if (td.IsEnum(metadata, out var underlyingType)) {
this.Kind = TypeKind.Enum; this.Kind = TypeKind.Enum;
this.EnumUnderlyingType = assembly.Compilation.FindType(underlyingType.ToKnownTypeCode()); this.EnumUnderlyingType = module.Compilation.FindType(underlyingType.ToKnownTypeCode());
} else if (td.IsValueType(metadata)) { } else if (td.IsValueType(metadata)) {
if (KnownTypeCode == KnownTypeCode.Void) { if (KnownTypeCode == KnownTypeCode.Void) {
this.Kind = TypeKind.Void; this.Kind = TypeKind.Void;
@ -121,11 +121,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
var nestedTypes = LazyInit.VolatileRead(ref this.nestedTypes); var nestedTypes = LazyInit.VolatileRead(ref this.nestedTypes);
if (nestedTypes != null) if (nestedTypes != null)
return nestedTypes; return nestedTypes;
var metadata = assembly.metadata; var metadata = module.metadata;
var nestedTypeCollection = metadata.GetTypeDefinition(handle).GetNestedTypes(); var nestedTypeCollection = metadata.GetTypeDefinition(handle).GetNestedTypes();
var nestedTypeList = new List<ITypeDefinition>(nestedTypeCollection.Length); var nestedTypeList = new List<ITypeDefinition>(nestedTypeCollection.Length);
foreach (TypeDefinitionHandle h in nestedTypeCollection) { foreach (TypeDefinitionHandle h in nestedTypeCollection) {
nestedTypeList.Add(assembly.GetDefinition(h)); nestedTypeList.Add(module.GetDefinition(h));
} }
return LazyInit.GetOrSet(ref this.nestedTypes, nestedTypeList.ToArray()); return LazyInit.GetOrSet(ref this.nestedTypes, nestedTypeList.ToArray());
} }
@ -147,14 +147,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
var fields = LazyInit.VolatileRead(ref this.fields); var fields = LazyInit.VolatileRead(ref this.fields);
if (fields != null) if (fields != null)
return fields; return fields;
var metadata = assembly.metadata; var metadata = module.metadata;
var fieldCollection = metadata.GetTypeDefinition(handle).GetFields(); var fieldCollection = metadata.GetTypeDefinition(handle).GetFields();
var fieldList = new List<IField>(fieldCollection.Count); var fieldList = new List<IField>(fieldCollection.Count);
foreach (FieldDefinitionHandle h in fieldCollection) { foreach (FieldDefinitionHandle h in fieldCollection) {
var field = metadata.GetFieldDefinition(h); var field = metadata.GetFieldDefinition(h);
var attr = field.Attributes; var attr = field.Attributes;
if (assembly.IsVisible(attr) && (attr & FieldAttributes.SpecialName) == 0) { if (module.IsVisible(attr) && (attr & FieldAttributes.SpecialName) == 0) {
fieldList.Add(assembly.GetDefinition(h)); fieldList.Add(module.GetDefinition(h));
} }
} }
return LazyInit.GetOrSet(ref this.fields, fieldList.ToArray()); return LazyInit.GetOrSet(ref this.fields, fieldList.ToArray());
@ -166,16 +166,16 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
var properties = LazyInit.VolatileRead(ref this.properties); var properties = LazyInit.VolatileRead(ref this.properties);
if (properties != null) if (properties != null)
return properties; return properties;
var metadata = assembly.metadata; var metadata = module.metadata;
var propertyCollection = metadata.GetTypeDefinition(handle).GetProperties(); var propertyCollection = metadata.GetTypeDefinition(handle).GetProperties();
var propertyList = new List<IProperty>(propertyCollection.Count); var propertyList = new List<IProperty>(propertyCollection.Count);
foreach (PropertyDefinitionHandle h in propertyCollection) { foreach (PropertyDefinitionHandle h in propertyCollection) {
var property = metadata.GetPropertyDefinition(h); var property = metadata.GetPropertyDefinition(h);
var accessors = property.GetAccessors(); var accessors = property.GetAccessors();
bool getterVisible = !accessors.Getter.IsNil && assembly.IsVisible(metadata.GetMethodDefinition(accessors.Getter).Attributes); bool getterVisible = !accessors.Getter.IsNil && module.IsVisible(metadata.GetMethodDefinition(accessors.Getter).Attributes);
bool setterVisible = !accessors.Setter.IsNil && assembly.IsVisible(metadata.GetMethodDefinition(accessors.Setter).Attributes); bool setterVisible = !accessors.Setter.IsNil && module.IsVisible(metadata.GetMethodDefinition(accessors.Setter).Attributes);
if (getterVisible || setterVisible) { if (getterVisible || setterVisible) {
propertyList.Add(assembly.GetDefinition(h)); propertyList.Add(module.GetDefinition(h));
} }
} }
return LazyInit.GetOrSet(ref this.properties, propertyList.ToArray()); return LazyInit.GetOrSet(ref this.properties, propertyList.ToArray());
@ -187,7 +187,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
var events = LazyInit.VolatileRead(ref this.events); var events = LazyInit.VolatileRead(ref this.events);
if (events != null) if (events != null)
return events; return events;
var metadata = assembly.metadata; var metadata = module.metadata;
var eventCollection = metadata.GetTypeDefinition(handle).GetEvents(); var eventCollection = metadata.GetTypeDefinition(handle).GetEvents();
var eventList = new List<IEvent>(eventCollection.Count); var eventList = new List<IEvent>(eventCollection.Count);
foreach (EventDefinitionHandle h in eventCollection) { foreach (EventDefinitionHandle h in eventCollection) {
@ -196,8 +196,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
if (accessors.Adder.IsNil) if (accessors.Adder.IsNil)
continue; continue;
var addMethod = metadata.GetMethodDefinition(accessors.Adder); var addMethod = metadata.GetMethodDefinition(accessors.Adder);
if (assembly.IsVisible(addMethod.Attributes)) { if (module.IsVisible(addMethod.Attributes)) {
eventList.Add(assembly.GetDefinition(h)); eventList.Add(module.GetDefinition(h));
} }
} }
return LazyInit.GetOrSet(ref this.events, eventList.ToArray()); return LazyInit.GetOrSet(ref this.events, eventList.ToArray());
@ -209,14 +209,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
var methods = LazyInit.VolatileRead(ref this.methods); var methods = LazyInit.VolatileRead(ref this.methods);
if (methods != null) if (methods != null)
return methods; return methods;
var metadata = assembly.metadata; var metadata = module.metadata;
var methodsCollection = metadata.GetTypeDefinition(handle).GetMethods(); var methodsCollection = metadata.GetTypeDefinition(handle).GetMethods();
var methodsList = new List<IMethod>(methodsCollection.Count); var methodsList = new List<IMethod>(methodsCollection.Count);
var methodSemantics = assembly.PEFile.MethodSemanticsLookup; var methodSemantics = module.PEFile.MethodSemanticsLookup;
foreach (MethodDefinitionHandle h in methodsCollection) { foreach (MethodDefinitionHandle h in methodsCollection) {
var md = metadata.GetMethodDefinition(h); var md = metadata.GetMethodDefinition(h);
if (methodSemantics.GetSemantics(h).Item2 == 0 && assembly.IsVisible(md.Attributes)) { if (methodSemantics.GetSemantics(h).Item2 == 0 && module.IsVisible(md.Attributes)) {
methodsList.Add(assembly.GetDefinition(h)); methodsList.Add(module.GetDefinition(h));
} }
} }
if (this.Kind == TypeKind.Struct || this.Kind == TypeKind.Enum) { 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); var baseTypes = LazyInit.VolatileRead(ref this.directBaseTypes);
if (baseTypes != null) if (baseTypes != null)
return baseTypes; return baseTypes;
var metadata = assembly.metadata; var metadata = module.metadata;
var td = metadata.GetTypeDefinition(handle); var td = metadata.GetTypeDefinition(handle);
var context = new GenericContext(TypeParameters); var context = new GenericContext(TypeParameters);
var interfaceImplCollection = td.GetInterfaceImplementations(); var interfaceImplCollection = td.GetInterfaceImplementations();
baseTypes = new List<IType>(1 + interfaceImplCollection.Count); baseTypes = new List<IType>(1 + interfaceImplCollection.Count);
if (!td.BaseType.IsNil) { if (!td.BaseType.IsNil) {
baseTypes.Add(assembly.ResolveType(td.BaseType, context)); baseTypes.Add(module.ResolveType(td.BaseType, context));
} else if (Kind == TypeKind.Interface) { } else if (Kind == TypeKind.Interface) {
// td.BaseType.IsNil is always true for interfaces, // td.BaseType.IsNil is always true for interfaces,
// but the type system expects every interface to derive from System.Object as well. // 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) { foreach (var h in interfaceImplCollection) {
var iface = metadata.GetInterfaceImplementation(h); 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); return LazyInit.GetOrSet(ref this.directBaseTypes, baseTypes);
} }
@ -276,13 +276,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public FullTypeName FullTypeName => fullTypeName; public FullTypeName FullTypeName => fullTypeName;
public string Name => fullTypeName.Name; public string Name => fullTypeName.Name;
public IAssembly ParentAssembly => assembly; public IModule ParentModule => module;
#region Type Attributes #region Type Attributes
public IEnumerable<IAttribute> GetAttributes() public IEnumerable<IAttribute> GetAttributes()
{ {
var b = new AttributeListBuilder(assembly); var b = new AttributeListBuilder(module);
var metadata = assembly.metadata; var metadata = module.metadata;
var typeDefinition = metadata.GetTypeDefinition(handle); var typeDefinition = metadata.GetTypeDefinition(handle);
// SerializableAttribute // SerializableAttribute
@ -318,7 +318,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
var layout = typeDefinition.GetLayout(); var layout = typeDefinition.GetLayout();
LayoutKind defaultLayoutKind = Kind == TypeKind.Struct ? LayoutKind.Sequential : LayoutKind.Auto; LayoutKind defaultLayoutKind = Kind == TypeKind.Struct ? LayoutKind.Sequential : LayoutKind.Auto;
if (layoutKind != defaultLayoutKind || charSet != CharSet.Ansi || layout.PackingSize > 0 || layout.Size > 0) { 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( structLayout.AddFixedArg(
new TopLevelTypeName("System.Runtime.InteropServices", "LayoutKind"), new TopLevelTypeName("System.Runtime.InteropServices", "LayoutKind"),
(int)layoutKind); (int)layoutKind);
@ -347,13 +347,13 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
string defaultMemberName = LazyInit.VolatileRead(ref this.defaultMemberName); string defaultMemberName = LazyInit.VolatileRead(ref this.defaultMemberName);
if (defaultMemberName != null) if (defaultMemberName != null)
return defaultMemberName; return defaultMemberName;
var metadata = assembly.metadata; var metadata = module.metadata;
var typeDefinition = metadata.GetTypeDefinition(handle); var typeDefinition = metadata.GetTypeDefinition(handle);
foreach (var h in typeDefinition.GetCustomAttributes()) { foreach (var h in typeDefinition.GetCustomAttributes()) {
var a = metadata.GetCustomAttribute(h); var a = metadata.GetCustomAttribute(h);
if (!a.IsKnownAttribute(metadata, KnownAttribute.DefaultMember)) if (!a.IsKnownAttribute(metadata, KnownAttribute.DefaultMember))
continue; 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) { if (value.FixedArguments.Length == 1 && value.FixedArguments[0].Value is string name) {
defaultMemberName = name; defaultMemberName = name;
break; break;
@ -393,7 +393,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public SymbolKind SymbolKind => SymbolKind.TypeDefinition; public SymbolKind SymbolKind => SymbolKind.TypeDefinition;
public ICompilation Compilation => assembly.Compilation; public ICompilation Compilation => module.Compilation;
public string FullName { public string FullName {
get { get {
@ -425,14 +425,14 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is MetadataTypeDefinition td) { 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; return false;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
return 0x2e0520f2 ^ assembly.PEFile.GetHashCode() ^ handle.GetHashCode(); return 0x2e0520f2 ^ module.PEFile.GetHashCode() ^ handle.GetHashCode();
} }
bool IEquatable<IType>.Equals(IType other) bool IEquatable<IType>.Equals(IType other)
@ -595,18 +595,18 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
#region GetOverrides #region GetOverrides
internal IEnumerable<IMethod> GetOverrides(MethodDefinitionHandle method) internal IEnumerable<IMethod> GetOverrides(MethodDefinitionHandle method)
{ {
var metadata = assembly.metadata; var metadata = module.metadata;
var td = metadata.GetTypeDefinition(handle); var td = metadata.GetTypeDefinition(handle);
foreach (var implHandle in td.GetMethodImplementations()) { foreach (var implHandle in td.GetMethodImplementations()) {
var impl = metadata.GetMethodImplementation(implHandle); var impl = metadata.GetMethodImplementation(implHandle);
if (impl.MethodBody == method) 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) internal bool HasOverrides(MethodDefinitionHandle method)
{ {
var metadata = assembly.metadata; var metadata = module.metadata;
var td = metadata.GetTypeDefinition(handle); var td = metadata.GetTypeDefinition(handle);
foreach (var implHandle in td.GetMethodImplementations()) { foreach (var implHandle in td.GetMethodImplementations()) {
var impl = metadata.GetMethodImplementation(implHandle); var impl = metadata.GetMethodImplementation(implHandle);

32
ICSharpCode.Decompiler/TypeSystem/Implementation/MetadataTypeParameter.cs

@ -28,7 +28,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
{ {
sealed class MetadataTypeParameter : AbstractTypeParameter sealed class MetadataTypeParameter : AbstractTypeParameter
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly GenericParameterHandle handle; readonly GenericParameterHandle handle;
readonly GenericParameterAttributes attr; readonly GenericParameterAttributes attr;
@ -36,7 +36,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
// lazy-loaded: // lazy-loaded:
IReadOnlyList<IType> constraints; IReadOnlyList<IType> 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) if (handles.Count == 0)
return Empty<ITypeParameter>.Array; return Empty<ITypeParameter>.Array;
@ -47,38 +47,38 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
if (i < outerTps.Count) if (i < outerTps.Count)
tps[i] = outerTps[i]; tps[i] = outerTps[i];
else else
tps[i] = Create(assembly, owner, i, handle); tps[i] = Create(module, owner, i, handle);
i++; i++;
} }
return tps; 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) if (handles.Count == 0)
return Empty<ITypeParameter>.Array; return Empty<ITypeParameter>.Array;
var tps = new ITypeParameter[handles.Count]; var tps = new ITypeParameter[handles.Count];
int i = 0; int i = 0;
foreach (var handle in handles) { foreach (var handle in handles) {
tps[i] = Create(assembly, owner, i, handle); tps[i] = Create(module, owner, i, handle);
i++; i++;
} }
return tps; 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); var gp = metadata.GetGenericParameter(handle);
Debug.Assert(gp.Index == index); 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) GenericParameterHandle handle, GenericParameterAttributes attr)
: base(owner, index, name, GetVariance(attr)) : base(owner, index, name, GetVariance(attr))
{ {
this.assembly = assembly; this.module = module;
this.handle = handle; this.handle = handle;
this.attr = attr; this.attr = attr;
} }
@ -99,11 +99,11 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public override IEnumerable<IAttribute> GetAttributes() public override IEnumerable<IAttribute> GetAttributes()
{ {
var metadata = assembly.metadata; var metadata = module.metadata;
var gp = metadata.GetGenericParameter(handle); var gp = metadata.GetGenericParameter(handle);
var attributes = gp.GetCustomAttributes(); var attributes = gp.GetCustomAttributes();
var b = new AttributeListBuilder(assembly, attributes.Count); var b = new AttributeListBuilder(module, attributes.Count);
b.Add(attributes); b.Add(attributes);
return b.Build(); return b.Build();
} }
@ -123,7 +123,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
private IReadOnlyList<IType> DecodeConstraints() private IReadOnlyList<IType> DecodeConstraints()
{ {
var metadata = assembly.metadata; var metadata = module.metadata;
var gp = metadata.GetGenericParameter(handle); var gp = metadata.GetGenericParameter(handle);
var constraintHandleCollection = gp.GetConstraints(); var constraintHandleCollection = gp.GetConstraints();
@ -131,7 +131,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
bool hasNonInterfaceConstraint = false; bool hasNonInterfaceConstraint = false;
foreach (var constraintHandle in constraintHandleCollection) { foreach (var constraintHandle in constraintHandleCollection) {
var constraint = metadata.GetGenericParameterConstraint(constraintHandle); 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); result.Add(ty);
hasNonInterfaceConstraint |= (ty.Kind != TypeKind.Interface); hasNonInterfaceConstraint |= (ty.Kind != TypeKind.Interface);
} }
@ -145,12 +145,12 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public override int GetHashCode() public override int GetHashCode()
{ {
return 0x51fc5b83 ^ assembly.PEFile.GetHashCode() ^ handle.GetHashCode(); return 0x51fc5b83 ^ module.PEFile.GetHashCode() ^ handle.GetHashCode();
} }
public override bool Equals(IType other) 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() public override string ToString()

30
ICSharpCode.Decompiler/TypeSystem/Implementation/MinimalCorlib.cs

@ -29,9 +29,9 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
/// An artificial "assembly" that contains all known types (<see cref="KnownTypeCode"/>) and no other types. /// An artificial "assembly" that contains all known types (<see cref="KnownTypeCode"/>) and no other types.
/// It does not contain any members. /// It does not contain any members.
/// </summary> /// </summary>
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; } public ICompilation Compilation { get; }
CorlibTypeDefinition[] typeDefinitions; 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 IModule.AssemblyName => "corlib";
string IAssembly.FullAssemblyName => "corlib"; string IModule.FullAssemblyName => "corlib";
Metadata.PEFile IAssembly.PEFile => null; Metadata.PEFile IModule.PEFile => null;
INamespace IAssembly.RootNamespace => rootNamespace; INamespace IModule.RootNamespace => rootNamespace;
public IEnumerable<ITypeDefinition> TopLevelTypeDefinitions => typeDefinitions.Where(td => td != null); public IEnumerable<ITypeDefinition> TopLevelTypeDefinitions => typeDefinitions.Where(td => td != null);
public IEnumerable<ITypeDefinition> TypeDefinitions => TopLevelTypeDefinitions; public IEnumerable<ITypeDefinition> TypeDefinitions => TopLevelTypeDefinitions;
@ -69,17 +69,17 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
return null; return null;
} }
IEnumerable<IAttribute> IAssembly.GetAssemblyAttributes() => EmptyList<IAttribute>.Instance; IEnumerable<IAttribute> IModule.GetAssemblyAttributes() => EmptyList<IAttribute>.Instance;
IEnumerable<IAttribute> IAssembly.GetModuleAttributes() => EmptyList<IAttribute>.Instance; IEnumerable<IAttribute> IModule.GetModuleAttributes() => EmptyList<IAttribute>.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); return new MinimalCorlib(context.Compilation);
} }
@ -106,7 +106,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
IEnumerable<INamespace> INamespace.ChildNamespaces => childNamespaces; IEnumerable<INamespace> INamespace.ChildNamespaces => childNamespaces;
IEnumerable<ITypeDefinition> INamespace.Types => corlib.TopLevelTypeDefinitions.Where(td => td.Namespace == FullName); IEnumerable<ITypeDefinition> INamespace.Types => corlib.TopLevelTypeDefinitions.Where(td => td.Namespace == FullName);
IEnumerable<IAssembly> INamespace.ContributingAssemblies => new[] { corlib }; IEnumerable<IModule> INamespace.ContributingModules => new[] { corlib };
SymbolKind ISymbol.SymbolKind => SymbolKind.Namespace; SymbolKind ISymbol.SymbolKind => SymbolKind.Namespace;
ICompilation ICompilationProvider.Compilation => corlib.Compilation; ICompilation ICompilationProvider.Compilation => corlib.Compilation;
@ -191,7 +191,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public string Name => KnownTypeReference.Get(typeCode).Name; public string Name => KnownTypeReference.Get(typeCode).Name;
IAssembly IEntity.ParentAssembly => corlib; IModule IEntity.ParentModule => corlib;
Accessibility IEntity.Accessibility => Accessibility.Public; Accessibility IEntity.Accessibility => Accessibility.Public;

67
ICSharpCode.Decompiler/TypeSystem/Implementation/TypeSpecification.cs → ICSharpCode.Decompiler/TypeSystem/Implementation/PinnedType.cs

@ -48,71 +48,4 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
return new PinnedType(newType); 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));
}
}
} }

36
ICSharpCode.Decompiler/TypeSystem/Implementation/SimpleCompilation.cs

@ -30,29 +30,29 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
readonly ITypeResolveContext context; readonly ITypeResolveContext context;
readonly CacheManager cacheManager = new CacheManager(); readonly CacheManager cacheManager = new CacheManager();
readonly KnownTypeCache knownTypeCache; readonly KnownTypeCache knownTypeCache;
readonly IAssembly mainAssembly; readonly IModule mainModule;
readonly IList<IAssembly> assemblies; readonly IList<IModule> assemblies;
readonly IList<IAssembly> referencedAssemblies; readonly IList<IModule> referencedAssemblies;
INamespace rootNamespace; INamespace rootNamespace;
public SimpleCompilation(IAssemblyReference mainAssembly, params IAssemblyReference[] assemblyReferences) public SimpleCompilation(IModuleReference mainAssembly, params IModuleReference[] assemblyReferences)
: this(mainAssembly, (IEnumerable<IAssemblyReference>)assemblyReferences) : this(mainAssembly, (IEnumerable<IModuleReference>)assemblyReferences)
{ {
} }
public SimpleCompilation(IAssemblyReference mainAssembly, IEnumerable<IAssemblyReference> assemblyReferences) public SimpleCompilation(IModuleReference mainAssembly, IEnumerable<IModuleReference> assemblyReferences)
{ {
if (mainAssembly == null) if (mainAssembly == null)
throw new ArgumentNullException("mainAssembly"); throw new ArgumentNullException("mainAssembly");
if (assemblyReferences == null) if (assemblyReferences == null)
throw new ArgumentNullException("assemblyReferences"); throw new ArgumentNullException("assemblyReferences");
this.context = new SimpleTypeResolveContext(this); this.context = new SimpleTypeResolveContext(this);
this.mainAssembly = mainAssembly.Resolve(context); this.mainModule = mainAssembly.Resolve(context);
List<IAssembly> assemblies = new List<IAssembly>(); List<IModule> assemblies = new List<IModule>();
assemblies.Add(this.mainAssembly); assemblies.Add(this.mainModule);
List<IAssembly> referencedAssemblies = new List<IAssembly>(); List<IModule> referencedAssemblies = new List<IModule>();
foreach (var asmRef in assemblyReferences) { foreach (var asmRef in assemblyReferences) {
IAssembly asm; IModule asm;
try { try {
asm = asmRef.Resolve(context); asm = asmRef.Resolve(context);
} catch (InvalidOperationException) { } catch (InvalidOperationException) {
@ -68,15 +68,15 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
this.knownTypeCache = new KnownTypeCache(this); this.knownTypeCache = new KnownTypeCache(this);
} }
public IAssembly MainAssembly { public IModule MainModule {
get { get {
if (mainAssembly == null) if (mainModule == null)
throw new InvalidOperationException("Compilation isn't initialized yet"); throw new InvalidOperationException("Compilation isn't initialized yet");
return mainAssembly; return mainModule;
} }
} }
public IList<IAssembly> Assemblies { public IList<IModule> Modules {
get { get {
if (assemblies == null) if (assemblies == null)
throw new InvalidOperationException("Compilation isn't initialized yet"); throw new InvalidOperationException("Compilation isn't initialized yet");
@ -84,7 +84,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
} }
} }
public IList<IAssembly> ReferencedAssemblies { public IList<IModule> ReferencedModules {
get { get {
if (referencedAssemblies == null) if (referencedAssemblies == null)
throw new InvalidOperationException("Compilation isn't initialized yet"); 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. // SimpleCompilation does not support extern aliases; but derived classes might.
// CreateRootNamespace() is virtual so that derived classes can change the global namespace. // CreateRootNamespace() is virtual so that derived classes can change the global namespace.
INamespace[] namespaces = new INamespace[referencedAssemblies.Count + 1]; INamespace[] namespaces = new INamespace[referencedAssemblies.Count + 1];
namespaces[0] = mainAssembly.RootNamespace; namespaces[0] = mainModule.RootNamespace;
for (int i = 0; i < referencedAssemblies.Count; i++) { for (int i = 0; i < referencedAssemblies.Count; i++) {
namespaces[i + 1] = referencedAssemblies[i].RootNamespace; namespaces[i + 1] = referencedAssemblies[i].RootNamespace;
} }
@ -144,7 +144,7 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
public override string ToString() public override string ToString()
{ {
return "[SimpleCompilation " + mainAssembly.AssemblyName + "]"; return "[SimpleCompilation " + mainModule.AssemblyName + "]";
} }
} }
} }

4
ICSharpCode.Decompiler/TypeSystem/Implementation/SpecializedMember.cs

@ -201,8 +201,8 @@ namespace ICSharpCode.Decompiler.TypeSystem.Implementation
get { return baseMember.Compilation; } get { return baseMember.Compilation; }
} }
public IAssembly ParentAssembly { public IModule ParentModule {
get { return baseMember.ParentAssembly; } get { return baseMember.ParentModule; }
} }
public virtual IMember Specialize(TypeParameterSubstitution newSubstitution) public virtual IMember Specialize(TypeParameterSubstitution newSubstitution)

29
ICSharpCode.Decompiler/TypeSystem/MetadataAssembly.cs → ICSharpCode.Decompiler/TypeSystem/MetadataModule.cs

@ -31,11 +31,10 @@ using ICSharpCode.Decompiler.Util;
namespace ICSharpCode.Decompiler.TypeSystem namespace ICSharpCode.Decompiler.TypeSystem
{ {
/// <summary> /// <summary>
/// Used as context object for metadata TS entities; /// Type system implementation for Metadata.PEFile.
/// should be turned into IAssembly implementation when the TS refactoring is complete.
/// </summary> /// </summary>
[DebuggerDisplay("<MetadataAssembly: {AssemblyName}>")] [DebuggerDisplay("<MetadataModule: {AssemblyName}>")]
public class MetadataAssembly : IAssembly public class MetadataModule : IModule
{ {
public ICompilation Compilation { get; } public ICompilation Compilation { get; }
internal readonly MetadataReader metadata; internal readonly MetadataReader metadata;
@ -49,7 +48,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
readonly MetadataProperty[] propertyDefs; readonly MetadataProperty[] propertyDefs;
readonly MetadataEvent[] eventDefs; 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.Compilation = compilation;
this.PEFile = peFile; this.PEFile = peFile;
@ -87,7 +86,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
#region IAssembly interface #region IAssembly interface
public PEFile PEFile { get; } public PEFile PEFile { get; }
public bool IsMainAssembly => this == Compilation.MainAssembly; public bool IsMainModule => this == Compilation.MainModule;
public string AssemblyName { get; } public string AssemblyName { get; }
public string FullAssemblyName { get; } public string FullAssemblyName { get; }
@ -111,12 +110,12 @@ namespace ICSharpCode.Decompiler.TypeSystem
#endregion #endregion
#region InternalsVisibleTo #region InternalsVisibleTo
public bool InternalsVisibleTo(IAssembly assembly) public bool InternalsVisibleTo(IModule module)
{ {
if (this == assembly) if (this == module)
return true; return true;
foreach (string shortName in GetInternalsVisibleTo()) { foreach (string shortName in GetInternalsVisibleTo()) {
if (string.Equals(assembly.AssemblyName, shortName, StringComparison.OrdinalIgnoreCase)) if (string.Equals(module.AssemblyName, shortName, StringComparison.OrdinalIgnoreCase))
return true; return true;
} }
return false; return false;
@ -572,13 +571,13 @@ namespace ICSharpCode.Decompiler.TypeSystem
IType ResolveForwardedType(ExportedType forwarder) IType ResolveForwardedType(ExportedType forwarder)
{ {
IAssembly assembly = ResolveAssembly(forwarder); IModule module = ResolveModule(forwarder);
var typeName = forwarder.GetFullTypeName(metadata); var typeName = forwarder.GetFullTypeName(metadata);
if (assembly == null) if (module == null)
return new UnknownType(typeName); return new UnknownType(typeName);
using (var busyLock = BusyManager.Enter(this)) { using (var busyLock = BusyManager.Enter(this)) {
if (busyLock.Success) { if (busyLock.Success) {
var td = assembly.GetTypeDefinition(typeName); var td = module.GetTypeDefinition(typeName);
if (td != null) { if (td != null) {
return td; return td;
} }
@ -586,7 +585,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
} }
return new UnknownType(typeName); return new UnknownType(typeName);
IAssembly ResolveAssembly(ExportedType type) IModule ResolveModule(ExportedType type)
{ {
switch (type.Implementation.Kind) { switch (type.Implementation.Kind) {
case HandleKind.AssemblyFile: case HandleKind.AssemblyFile:
@ -594,11 +593,11 @@ namespace ICSharpCode.Decompiler.TypeSystem
return this; return this;
case HandleKind.ExportedType: case HandleKind.ExportedType:
var outerType = metadata.GetExportedType((ExportedTypeHandle)type.Implementation); var outerType = metadata.GetExportedType((ExportedTypeHandle)type.Implementation);
return ResolveAssembly(outerType); return ResolveModule(outerType);
case HandleKind.AssemblyReference: case HandleKind.AssemblyReference:
var asmRef = metadata.GetAssemblyReference((AssemblyReferenceHandle)type.Implementation); var asmRef = metadata.GetAssemblyReference((AssemblyReferenceHandle)type.Implementation);
string shortName = metadata.GetString(asmRef.Name); 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)) { if (string.Equals(asm.AssemblyName, shortName, StringComparison.OrdinalIgnoreCase)) {
return asm; return asm;
} }

6
ICSharpCode.Decompiler/TypeSystem/ReflectionHelper.cs

@ -110,7 +110,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount); string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
return new NestedTypeReference(baseTypeRef, name, typeParameterCount); return new NestedTypeReference(baseTypeRef, name, typeParameterCount);
} else { } else {
IAssemblyReference assemblyReference = new DefaultAssemblyReference(type.Assembly.FullName); IModuleReference assemblyReference = new DefaultAssemblyReference(type.Assembly.FullName);
int typeParameterCount; int typeParameterCount;
string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount); string name = SplitTypeParameterCountFromReflectionName(type.Name, out typeParameterCount);
return new GetClassTypeReference(assemblyReference, type.Namespace, name, 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 /// For looking up closed, assembly qualified type names, the root type resolve context for the compilation
/// is sufficient. /// is sufficient.
/// When looking up a type name that isn't assembly qualified, the type reference will look in /// When looking up a type name that isn't assembly qualified, the type reference will look in
/// <see cref="ITypeResolveContext.CurrentAssembly"/> first, and if the type is not found there, /// <see cref="ITypeResolveContext.CurrentModule"/> first, and if the type is not found there,
/// it will look in all other assemblies of the compilation. /// it will look in all other assemblies of the compilation.
/// </remarks> /// </remarks>
/// <seealso cref="FullTypeName(string)"/> /// <seealso cref="FullTypeName(string)"/>
@ -347,7 +347,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
static ITypeReference CreateGetClassTypeReference(string assemblyName, string typeName, int tpc) static ITypeReference CreateGetClassTypeReference(string assemblyName, string typeName, int tpc)
{ {
IAssemblyReference assemblyReference; IModuleReference assemblyReference;
if (assemblyName != null) { if (assemblyName != null) {
assemblyReference = new DefaultAssemblyReference(assemblyName); assemblyReference = new DefaultAssemblyReference(assemblyName);
} else { } else {

26
ICSharpCode.Decompiler/TypeSystem/SimpleTypeResolveContext.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public class SimpleTypeResolveContext : ITypeResolveContext public class SimpleTypeResolveContext : ITypeResolveContext
{ {
readonly ICompilation compilation; readonly ICompilation compilation;
readonly IAssembly currentAssembly; readonly IModule currentModule;
readonly ITypeDefinition currentTypeDefinition; readonly ITypeDefinition currentTypeDefinition;
readonly IMember currentMember; readonly IMember currentMember;
@ -37,12 +37,12 @@ namespace ICSharpCode.Decompiler.TypeSystem
this.compilation = compilation; this.compilation = compilation;
} }
public SimpleTypeResolveContext(IAssembly assembly) public SimpleTypeResolveContext(IModule module)
{ {
if (assembly == null) if (module == null)
throw new ArgumentNullException("assembly"); throw new ArgumentNullException(nameof(module));
this.compilation = assembly.Compilation; this.compilation = module.Compilation;
this.currentAssembly = assembly; this.currentModule = module;
} }
public SimpleTypeResolveContext(IEntity entity) public SimpleTypeResolveContext(IEntity entity)
@ -50,15 +50,15 @@ namespace ICSharpCode.Decompiler.TypeSystem
if (entity == null) if (entity == null)
throw new ArgumentNullException("entity"); throw new ArgumentNullException("entity");
this.compilation = entity.Compilation; this.compilation = entity.Compilation;
this.currentAssembly = entity.ParentAssembly; this.currentModule = entity.ParentModule;
this.currentTypeDefinition = (entity as ITypeDefinition) ?? entity.DeclaringTypeDefinition; this.currentTypeDefinition = (entity as ITypeDefinition) ?? entity.DeclaringTypeDefinition;
this.currentMember = entity as IMember; 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.compilation = compilation;
this.currentAssembly = currentAssembly; this.currentModule = currentModule;
this.currentTypeDefinition = currentTypeDefinition; this.currentTypeDefinition = currentTypeDefinition;
this.currentMember = currentMember; this.currentMember = currentMember;
} }
@ -67,8 +67,8 @@ namespace ICSharpCode.Decompiler.TypeSystem
get { return compilation; } get { return compilation; }
} }
public IAssembly CurrentAssembly { public IModule CurrentModule {
get { return currentAssembly; } get { return currentModule; }
} }
public ITypeDefinition CurrentTypeDefinition { public ITypeDefinition CurrentTypeDefinition {
@ -81,12 +81,12 @@ namespace ICSharpCode.Decompiler.TypeSystem
public ITypeResolveContext WithCurrentTypeDefinition(ITypeDefinition typeDefinition) public ITypeResolveContext WithCurrentTypeDefinition(ITypeDefinition typeDefinition)
{ {
return new SimpleTypeResolveContext(compilation, currentAssembly, typeDefinition, currentMember); return new SimpleTypeResolveContext(compilation, currentModule, typeDefinition, currentMember);
} }
public ITypeResolveContext WithCurrentMember(IMember member) public ITypeResolveContext WithCurrentMember(IMember member)
{ {
return new SimpleTypeResolveContext(compilation, currentAssembly, currentTypeDefinition, member); return new SimpleTypeResolveContext(compilation, currentModule, currentTypeDefinition, member);
} }
} }
} }

6
ICSharpCode.Decompiler/TypeSystem/SpecializingDecompilerTypeSystem.cs

@ -51,6 +51,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
} }
public Metadata.PEFile ModuleDefinition => context.ModuleDefinition; public Metadata.PEFile ModuleDefinition => context.ModuleDefinition;
public MetadataModule MainModule => context.MainModule;
public TypeParameterSubstitution Substitution { public TypeParameterSubstitution Substitution {
get { return substitution; } get { return substitution; }
@ -98,11 +99,6 @@ namespace ICSharpCode.Decompiler.TypeSystem
return member; return member;
} }
public PEFile GetModuleDefinition(IAssembly assembly)
{
return context.GetModuleDefinition(assembly);
}
MethodSignature<IType> IDecompilerTypeSystem.DecodeMethodSignature(StandaloneSignatureHandle standaloneSignatureHandle) MethodSignature<IType> IDecompilerTypeSystem.DecodeMethodSignature(StandaloneSignatureHandle standaloneSignatureHandle)
{ {
var sig = context.DecodeMethodSignature(standaloneSignatureHandle); var sig = context.DecodeMethodSignature(standaloneSignatureHandle);

14
ICSharpCode.Decompiler/TypeSystem/TupleType.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public TupleType(ICompilation compilation, ImmutableArray<IType> elementTypes, public TupleType(ICompilation compilation, ImmutableArray<IType> elementTypes,
ImmutableArray<string> elementNames = default(ImmutableArray<string>), ImmutableArray<string> elementNames = default(ImmutableArray<string>),
IAssembly valueTupleAssembly = null) IModule valueTupleAssembly = null)
{ {
this.Compilation = compilation; this.Compilation = compilation;
this.UnderlyingType = CreateUnderlyingType(compilation, elementTypes, valueTupleAssembly); this.UnderlyingType = CreateUnderlyingType(compilation, elementTypes, valueTupleAssembly);
@ -64,7 +64,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
} }
} }
static ParameterizedType CreateUnderlyingType(ICompilation compilation, ImmutableArray<IType> elementTypes, IAssembly valueTupleAssembly) static ParameterizedType CreateUnderlyingType(ICompilation compilation, ImmutableArray<IType> elementTypes, IModule valueTupleAssembly)
{ {
int remainder = (elementTypes.Length - 1) % (RestPosition - 1) + 1; int remainder = (elementTypes.Length - 1) % (RestPosition - 1) + 1;
Debug.Assert(remainder >= 1 && remainder < RestPosition); Debug.Assert(remainder >= 1 && remainder < RestPosition);
@ -82,7 +82,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
return type; 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); FullTypeName typeName = new TopLevelTypeName("System", "ValueTuple", tpc);
if (valueTupleAssembly != null) { if (valueTupleAssembly != null) {
@ -134,7 +134,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
return new TupleType( return new TupleType(
compilation, compilation,
elementTypes, elementTypes,
valueTupleAssembly: type.GetDefinition()?.ParentAssembly valueTupleAssembly: type.GetDefinition()?.ParentModule
); );
} else { } else {
return null; return null;
@ -252,7 +252,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
} }
if (newElementTypes != null) { if (newElementTypes != null) {
return new TupleType(this.Compilation, newElementTypes.ToImmutableArray(), this.ElementNames, return new TupleType(this.Compilation, newElementTypes.ToImmutableArray(), this.ElementNames,
this.GetDefinition()?.ParentAssembly); this.GetDefinition()?.ParentModule);
} else { } else {
return this; return this;
} }
@ -343,7 +343,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// </summary> /// </summary>
public ImmutableArray<string> ElementNames { get; } public ImmutableArray<string> ElementNames { get; }
public IAssemblyReference ValueTupleAssembly { get; } public IModuleReference ValueTupleAssembly { get; }
public TupleTypeReference(ImmutableArray<ITypeReference> elementTypes) public TupleTypeReference(ImmutableArray<ITypeReference> elementTypes)
{ {
@ -352,7 +352,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public TupleTypeReference(ImmutableArray<ITypeReference> elementTypes, public TupleTypeReference(ImmutableArray<ITypeReference> elementTypes,
ImmutableArray<string> elementNames = default(ImmutableArray<string>), ImmutableArray<string> elementNames = default(ImmutableArray<string>),
IAssemblyReference valueTupleAssembly = null) IModuleReference valueTupleAssembly = null)
{ {
this.ValueTupleAssembly = valueTupleAssembly; this.ValueTupleAssembly = valueTupleAssembly;
this.ElementTypes = elementTypes; this.ElementTypes = elementTypes;

18
ICSharpCode.Decompiler/TypeSystem/TypeProvider.cs

@ -32,13 +32,13 @@ namespace ICSharpCode.Decompiler.TypeSystem
SRM.ISignatureTypeProvider<IType, GenericContext>, SRM.ISignatureTypeProvider<IType, GenericContext>,
SRM.ICustomAttributeTypeProvider<IType> SRM.ICustomAttributeTypeProvider<IType>
{ {
readonly MetadataAssembly assembly; readonly MetadataModule module;
readonly ICompilation compilation; readonly ICompilation compilation;
public TypeProvider(IAssembly assembly) public TypeProvider(MetadataModule module)
{ {
this.assembly = (MetadataAssembly)assembly; // TODO: change parameter type instead of casting this.module = module;
this.compilation = assembly.Compilation; this.compilation = module.Compilation;
} }
public TypeProvider(ICompilation compilation) public TypeProvider(ICompilation compilation)
@ -122,7 +122,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
public IType GetTypeFromDefinition(SRM.MetadataReader reader, SRM.TypeDefinitionHandle handle, byte rawTypeKind) public IType GetTypeFromDefinition(SRM.MetadataReader reader, SRM.TypeDefinitionHandle handle, byte rawTypeKind)
{ {
ITypeDefinition td = assembly?.GetDefinition(handle); ITypeDefinition td = module?.GetDefinition(handle);
if (td != null) if (td != null)
return td; return td;
bool? isReferenceType = IsReferenceType(reader, handle, rawTypeKind); 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) 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); bool? isReferenceType = IsReferenceType(reader, handle, rawTypeKind);
var gctr = new GetClassTypeReference(handle.GetFullTypeName(reader), handle.GetDeclaringAssembly(reader), isReferenceType); var gctr = new GetClassTypeReference(handle.GetFullTypeName(reader), handle.GetDeclaringModule(reader), isReferenceType);
return gctr.Resolve(assembly != null ? new SimpleTypeResolveContext(assembly) : new SimpleTypeResolveContext(compilation)); return gctr.Resolve(module != null ? new SimpleTypeResolveContext(module) : new SimpleTypeResolveContext(compilation));
} }
public IType GetTypeFromSerializedName(string name) public IType GetTypeFromSerializedName(string name)
@ -143,7 +143,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
return null; return null;
} }
return ReflectionHelper.ParseReflectionName(name) 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) public IType GetTypeFromSpecification(SRM.MetadataReader reader, GenericContext genericContext, SRM.TypeSpecificationHandle handle, byte rawTypeKind)

20
ICSharpCode.Decompiler/TypeSystem/TypeSystemExtensions.cs

@ -262,7 +262,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// </summary> /// </summary>
public static IEnumerable<ITypeDefinition> GetAllTypeDefinitions (this ICompilation compilation) public static IEnumerable<ITypeDefinition> GetAllTypeDefinitions (this ICompilation compilation)
{ {
return compilation.Assemblies.SelectMany(a => a.TypeDefinitions); return compilation.Modules.SelectMany(a => a.TypeDefinitions);
} }
/// <summary> /// <summary>
@ -271,7 +271,7 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// </summary> /// </summary>
public static IEnumerable<ITypeDefinition> GetTopLevelTypeDefinitions (this ICompilation compilation) public static IEnumerable<ITypeDefinition> GetTopLevelTypeDefinitions (this ICompilation compilation)
{ {
return compilation.Assemblies.SelectMany(a => a.TopLevelTypeDefinitions); return compilation.Modules.SelectMany(a => a.TopLevelTypeDefinitions);
} }
#endregion #endregion
@ -299,14 +299,14 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// There can be multiple types with the same full name in a compilation, as a /// There can be multiple types with the same full name in a compilation, as a
/// full type name is only unique per assembly. /// full type name is only unique per assembly.
/// If there are multiple possible matches, this method will return just one of them. /// If there are multiple possible matches, this method will return just one of them.
/// When possible, use <see cref="IAssembly.GetTypeDefinition"/> instead to /// When possible, use <see cref="IModule.GetTypeDefinition"/> instead to
/// retrieve a type from a specific assembly. /// retrieve a type from a specific assembly.
/// </remarks> /// </remarks>
public static IType FindType(this ICompilation compilation, FullTypeName fullTypeName) public static IType FindType(this ICompilation compilation, FullTypeName fullTypeName)
{ {
if (compilation == null) if (compilation == null)
throw new ArgumentNullException("compilation"); throw new ArgumentNullException("compilation");
foreach (IAssembly asm in compilation.Assemblies) { foreach (IModule asm in compilation.Modules) {
ITypeDefinition def = asm.GetTypeDefinition(fullTypeName); ITypeDefinition def = asm.GetTypeDefinition(fullTypeName);
if (def != null) if (def != null)
return def; return def;
@ -318,12 +318,12 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the type definition for the specified unresolved type. /// Gets the type definition for the specified unresolved type.
/// Returns null if the unresolved type does not belong to this assembly. /// Returns null if the unresolved type does not belong to this assembly.
/// </summary> /// </summary>
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"); throw new ArgumentNullException("assembly");
TopLevelTypeName topLevelTypeName = fullTypeName.TopLevelTypeName; TopLevelTypeName topLevelTypeName = fullTypeName.TopLevelTypeName;
ITypeDefinition typeDef = assembly.GetTypeDefinition(topLevelTypeName); ITypeDefinition typeDef = module.GetTypeDefinition(topLevelTypeName);
if (typeDef == null) if (typeDef == null)
return null; return null;
int typeParameterCount = topLevelTypeName.TypeParameterCount; int typeParameterCount = topLevelTypeName.TypeParameterCount;
@ -418,11 +418,11 @@ namespace ICSharpCode.Decompiler.TypeSystem
/// Gets the type definition for a top-level type. /// Gets the type definition for a top-level type.
/// </summary> /// </summary>
/// <remarks>This method uses ordinal name comparison, not the compilation's name comparer.</remarks> /// <remarks>This method uses ordinal name comparison, not the compilation's name comparer.</remarks>
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"); throw new ArgumentNullException ("assembly");
return assembly.GetTypeDefinition (new TopLevelTypeName (namespaceName, name, typeParameterCount)); return module.GetTypeDefinition (new TopLevelTypeName (namespaceName, name, typeParameterCount));
} }
#endregion #endregion

4
ICSharpCode.Decompiler/TypeSystem/VarArgInstanceMethod.cs

@ -220,8 +220,8 @@ namespace ICSharpCode.Decompiler.TypeSystem
get { return baseMethod.DeclaringType; } get { return baseMethod.DeclaringType; }
} }
public IAssembly ParentAssembly { public IModule ParentModule {
get { return baseMethod.ParentAssembly; } get { return baseMethod.ParentModule; }
} }
public bool IsStatic { public bool IsStatic {

2
ILSpy.BamlDecompiler/CecilType.cs

@ -22,7 +22,7 @@ namespace ILSpy.BamlDecompiler
public string AssemblyQualifiedName { public string AssemblyQualifiedName {
get { get {
return type.FullName + return type.FullName +
", " + type.ParentAssembly.FullAssemblyName; ", " + type.ParentModule.FullAssemblyName;
} }
} }

2
ILSpy.BamlDecompiler/CecilTypeResolver.cs

@ -27,7 +27,7 @@ namespace ILSpy.BamlDecompiler
public bool IsLocalAssembly(string name) public bool IsLocalAssembly(string name)
{ {
return MakeShort(name) == compilation.MainAssembly.AssemblyName; return MakeShort(name) == compilation.MainModule.AssemblyName;
} }
string MakeShort(string name) string MakeShort(string name)

2
ILSpy/Analyzers/AnalyzerEntityTreeNode.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.ILSpy.Analyzers
public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies) public override bool HandleAssemblyListChanged(ICollection<LoadedAssembly> removedAssemblies, ICollection<LoadedAssembly> addedAssemblies)
{ {
foreach (LoadedAssembly asm in removedAssemblies) { foreach (LoadedAssembly asm in removedAssemblies) {
if (this.Member.ParentAssembly.PEFile == asm.GetPEFileOrNull()) if (this.Member.ParentModule.PEFile == asm.GetPEFileOrNull())
return false; // remove this node return false; // remove this node
} }
this.Children.RemoveAll( this.Children.RemoveAll(

2
ILSpy/Analyzers/AnalyzerSearchTreeNode.cs

@ -51,7 +51,7 @@ namespace ICSharpCode.ILSpy.Analyzers
protected IEnumerable<AnalyzerTreeNode> FetchChildren(CancellationToken ct) protected IEnumerable<AnalyzerTreeNode> FetchChildren(CancellationToken ct)
{ {
if (analyzer is IEntityAnalyzer<T> entityAnalyzer) { if (analyzer is IEntityAnalyzer<T> entityAnalyzer) {
var module = analyzedEntity.ParentAssembly.PEFile; var module = analyzedEntity.ParentModule.PEFile;
var ts = new DecompilerTypeSystem(module, module.GetAssemblyResolver()); var ts = new DecompilerTypeSystem(module, module.GetAssemblyResolver());
var context = new AnalyzerContext(ts) { var context = new AnalyzerContext(ts) {
CancellationToken = ct, CancellationToken = ct,

6
ILSpy/Analyzers/Builtin/EventImplementsInterfaceAnalyzer.cs

@ -34,14 +34,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
public IEnumerable<IEntity> Analyze(IEvent analyzedEntity, ITypeDefinition type, AnalyzerContext context) public IEnumerable<IEntity> Analyze(IEvent analyzedEntity, ITypeDefinition type, AnalyzerContext context)
{ {
var token = analyzedEntity.DeclaringTypeDefinition.MetadataToken; var token = analyzedEntity.DeclaringTypeDefinition.MetadataToken;
var module = analyzedEntity.DeclaringTypeDefinition.ParentAssembly.PEFile; var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.PEFile;
if (!type.GetAllBaseTypeDefinitions() if (!type.GetAllBaseTypeDefinitions()
.Any(t => t.MetadataToken == token && t.ParentAssembly.PEFile == module)) .Any(t => t.MetadataToken == token && t.ParentModule.PEFile == module))
yield break; yield break;
foreach (var @event in type.GetEvents(options: GetMemberOptions.ReturnMemberDefinitions)) { foreach (var @event in type.GetEvents(options: GetMemberOptions.ReturnMemberDefinitions)) {
if (InheritanceHelper.GetBaseMembers(@event, true) 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; yield return @event;
} }
} }

4
ILSpy/Analyzers/Builtin/EventOverriddenByAnalyzer.cs

@ -34,14 +34,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
public IEnumerable<IEntity> Analyze(IEvent analyzedEntity, ITypeDefinition type, AnalyzerContext context) public IEnumerable<IEntity> Analyze(IEvent analyzedEntity, ITypeDefinition type, AnalyzerContext context)
{ {
if (!analyzedEntity.DeclaringType.GetAllBaseTypeDefinitions() 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; yield break;
foreach (var property in type.Properties) { foreach (var property in type.Properties) {
if (!property.IsOverride) continue; if (!property.IsOverride) continue;
if (InheritanceHelper.GetBaseMembers(property, false) if (InheritanceHelper.GetBaseMembers(property, false)
.Any(p => p.MetadataToken == analyzedEntity.MetadataToken && .Any(p => p.MetadataToken == analyzedEntity.MetadataToken &&
p.ParentAssembly.PEFile == analyzedEntity.ParentAssembly.PEFile)) { p.ParentModule.PEFile == analyzedEntity.ParentModule.PEFile)) {
yield return property; yield return property;
} }
} }

2
ILSpy/Analyzers/Builtin/FieldAccessAnalyzer.cs

@ -89,7 +89,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
continue; continue;
found = field.MetadataToken == analyzedField.MetadataToken found = field.MetadataToken == analyzedField.MetadataToken
&& field.ParentAssembly.PEFile == analyzedField.ParentAssembly.PEFile; && field.ParentModule.PEFile == analyzedField.ParentModule.PEFile;
} }
if (found) { if (found) {

6
ILSpy/Analyzers/Builtin/MethodImplementsInterfaceAnalyzer.cs

@ -37,14 +37,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
public IEnumerable<IEntity> Analyze(IMethod analyzedEntity, ITypeDefinition type, AnalyzerContext context) public IEnumerable<IEntity> Analyze(IMethod analyzedEntity, ITypeDefinition type, AnalyzerContext context)
{ {
var token = analyzedEntity.DeclaringTypeDefinition.MetadataToken; var token = analyzedEntity.DeclaringTypeDefinition.MetadataToken;
var module = analyzedEntity.DeclaringTypeDefinition.ParentAssembly.PEFile; var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.PEFile;
if (!type.GetAllBaseTypeDefinitions() if (!type.GetAllBaseTypeDefinitions()
.Any(t => t.MetadataToken == token && t.ParentAssembly.PEFile == module)) .Any(t => t.MetadataToken == token && t.ParentModule.PEFile == module))
yield break; yield break;
foreach (var method in type.GetMethods(options: GetMemberOptions.ReturnMemberDefinitions)) { foreach (var method in type.GetMethods(options: GetMemberOptions.ReturnMemberDefinitions)) {
if (InheritanceHelper.GetBaseMembers(method, true) 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; yield return method;
} }
} }

4
ILSpy/Analyzers/Builtin/MethodOverriddenByAnalyzer.cs

@ -34,14 +34,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
public IEnumerable<IEntity> Analyze(IMethod analyzedEntity, ITypeDefinition type, AnalyzerContext context) public IEnumerable<IEntity> Analyze(IMethod analyzedEntity, ITypeDefinition type, AnalyzerContext context)
{ {
if (!analyzedEntity.DeclaringType.GetAllBaseTypeDefinitions() 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; yield break;
foreach (var property in type.Properties) { foreach (var property in type.Properties) {
if (!property.IsOverride) continue; if (!property.IsOverride) continue;
if (InheritanceHelper.GetBaseMembers(property, false) if (InheritanceHelper.GetBaseMembers(property, false)
.Any(p => p.MetadataToken == analyzedEntity.MetadataToken && .Any(p => p.MetadataToken == analyzedEntity.MetadataToken &&
p.ParentAssembly.PEFile == analyzedEntity.ParentAssembly.PEFile)) { p.ParentModule.PEFile == analyzedEntity.ParentModule.PEFile)) {
yield return property; yield return property;
} }
} }

2
ILSpy/Analyzers/Builtin/MethodUsedByAnalyzer.cs

@ -74,7 +74,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
static bool IsSameMember(IMember analyzedMethod, IMember m) static bool IsSameMember(IMember analyzedMethod, IMember m)
{ {
return m.MetadataToken == analyzedMethod.MetadataToken return m.MetadataToken == analyzedMethod.MetadataToken
&& m.ParentAssembly.PEFile == analyzedMethod.ParentAssembly.PEFile; && m.ParentModule.PEFile == analyzedMethod.ParentModule.PEFile;
} }
} }
} }

2
ILSpy/Analyzers/Builtin/MethodUsesAnalyzer.cs

@ -48,7 +48,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
IEnumerable<IEntity> ScanMethod(IMethod analyzedMethod, MethodDefinitionHandle handle, AnalyzerContext context) IEnumerable<IEntity> ScanMethod(IMethod analyzedMethod, MethodDefinitionHandle handle, AnalyzerContext context)
{ {
var module = analyzedMethod.ParentAssembly.PEFile; var module = analyzedMethod.ParentModule.PEFile;
var md = module.Metadata.GetMethodDefinition(handle); var md = module.Metadata.GetMethodDefinition(handle);
if (!md.HasBody()) yield break; if (!md.HasBody()) yield break;

2
ILSpy/Analyzers/Builtin/MethodVirtualUsedByAnalyzer.cs

@ -56,7 +56,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
case HandleKind.MethodSpecification: case HandleKind.MethodSpecification:
case HandleKind.MemberReference: case HandleKind.MemberReference:
var m = context.TypeSystem.ResolveAsMember(member)?.MemberDefinition; 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 return method;
yield break; yield break;
} }

6
ILSpy/Analyzers/Builtin/PropertyImplementsInterfaceAnalyzer.cs

@ -34,14 +34,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
public IEnumerable<IEntity> Analyze(IProperty analyzedEntity, ITypeDefinition type, AnalyzerContext context) public IEnumerable<IEntity> Analyze(IProperty analyzedEntity, ITypeDefinition type, AnalyzerContext context)
{ {
var token = analyzedEntity.DeclaringTypeDefinition.MetadataToken; var token = analyzedEntity.DeclaringTypeDefinition.MetadataToken;
var module = analyzedEntity.DeclaringTypeDefinition.ParentAssembly.PEFile; var module = analyzedEntity.DeclaringTypeDefinition.ParentModule.PEFile;
if (!type.GetAllBaseTypeDefinitions() if (!type.GetAllBaseTypeDefinitions()
.Any(t => t.MetadataToken == token && t.ParentAssembly.PEFile == module)) .Any(t => t.MetadataToken == token && t.ParentModule.PEFile == module))
yield break; yield break;
foreach (var property in type.GetProperties(options: GetMemberOptions.ReturnMemberDefinitions)) { foreach (var property in type.GetProperties(options: GetMemberOptions.ReturnMemberDefinitions)) {
if (InheritanceHelper.GetBaseMembers(property, true) 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; yield return property;
} }
} }

4
ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs

@ -37,14 +37,14 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
public IEnumerable<IEntity> Analyze(IProperty analyzedEntity, ITypeDefinition type, AnalyzerContext context) public IEnumerable<IEntity> Analyze(IProperty analyzedEntity, ITypeDefinition type, AnalyzerContext context)
{ {
if (!analyzedEntity.DeclaringType.GetAllBaseTypeDefinitions() 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; yield break;
foreach (var property in type.Properties) { foreach (var property in type.Properties) {
if (!property.IsOverride) continue; if (!property.IsOverride) continue;
if (InheritanceHelper.GetBaseMembers(property, false) if (InheritanceHelper.GetBaseMembers(property, false)
.Any(p => p.MetadataToken == analyzedEntity.MetadataToken && .Any(p => p.MetadataToken == analyzedEntity.MetadataToken &&
p.ParentAssembly.PEFile == analyzedEntity.ParentAssembly.PEFile)) { p.ParentModule.PEFile == analyzedEntity.ParentModule.PEFile)) {
yield return property; yield return property;
} }
} }

2
ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs

@ -40,7 +40,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
{ {
if (analyzedType.Kind == TypeKind.Enum if (analyzedType.Kind == TypeKind.Enum
&& type.MetadataToken == analyzedType.MetadataToken && type.MetadataToken == analyzedType.MetadataToken
&& type.ParentAssembly.PEFile == analyzedType.ParentAssembly.PEFile) && type.ParentModule.PEFile == analyzedType.ParentModule.PEFile)
yield break; yield break;
if (!context.Language.ShowMember(type)) if (!context.Language.ShowMember(type))

2
ILSpy/Analyzers/Builtin/TypeInstantiatedByAnalyzer.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
continue; continue;
found = ctor.DeclaringTypeDefinition?.MetadataToken == analyzedEntity.MetadataToken found = ctor.DeclaringTypeDefinition?.MetadataToken == analyzedEntity.MetadataToken
&& ctor.ParentAssembly.PEFile == analyzedEntity.ParentAssembly.PEFile; && ctor.ParentModule.PEFile == analyzedEntity.ParentModule.PEFile;
} }
if (found) { if (found) {

4
ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs

@ -141,7 +141,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
public IEnumerable<IEntity> Analyze(ITypeDefinition analyzedEntity, ITypeDefinition type, AnalyzerContext context) public IEnumerable<IEntity> 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) && analyzedEntity.MetadataToken == type.MetadataToken)
yield break; yield break;
@ -185,7 +185,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
public override IType VisitTypeDefinition(ITypeDefinition type) public override IType VisitTypeDefinition(ITypeDefinition type)
{ {
Found |= typeDefinition.MetadataToken == type.MetadataToken Found |= typeDefinition.MetadataToken == type.MetadataToken
&& typeDefinition.ParentAssembly.PEFile == type.ParentAssembly.PEFile; && typeDefinition.ParentModule.PEFile == type.ParentModule.PEFile;
return base.VisitTypeDefinition(type); return base.VisitTypeDefinition(type);
} }
} }

6
ILSpy/Analyzers/ScopedWhereUsedAnalyzer.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.ILSpy.Analyzers
{ {
readonly Language language; readonly Language language;
readonly IAnalyzer<T> analyzer; readonly IAnalyzer<T> analyzer;
readonly IAssembly assemblyScope; readonly IModule assemblyScope;
readonly T analyzedEntity; readonly T analyzedEntity;
ITypeDefinition typeScope; ITypeDefinition typeScope;
@ -47,7 +47,7 @@ namespace ICSharpCode.ILSpy.Analyzers
this.language = language ?? throw new ArgumentNullException(nameof(language)); this.language = language ?? throw new ArgumentNullException(nameof(language));
this.analyzer = analyzer ?? throw new ArgumentNullException(nameof(analyzer)); this.analyzer = analyzer ?? throw new ArgumentNullException(nameof(analyzer));
this.analyzedEntity = analyzedEntity; this.analyzedEntity = analyzedEntity;
this.assemblyScope = analyzedEntity.ParentAssembly; this.assemblyScope = analyzedEntity.ParentModule;
if (analyzedEntity is ITypeDefinition type) { if (analyzedEntity is ITypeDefinition type) {
this.typeScope = type; this.typeScope = type;
this.typeAccessibility = type.Accessibility; this.typeAccessibility = type.Accessibility;
@ -112,7 +112,7 @@ namespace ICSharpCode.ILSpy.Analyzers
{ {
var ts = new DecompilerTypeSystem(module, module.GetAssemblyResolver()); var ts = new DecompilerTypeSystem(module, module.GetAssemblyResolver());
var context = new AnalyzerContext(ts) { CancellationToken = ct, Language = language }; 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(); ct.ThrowIfCancellationRequested();
if (type.MetadataToken.IsNil) continue; if (type.MetadataToken.IsNil) continue;
context.CodeMappingInfo = language.GetCodeMappingInfo(module, type.MetadataToken); context.CodeMappingInfo = language.GetCodeMappingInfo(module, type.MetadataToken);

14
ILSpy/Languages/CSharpLanguage.cs

@ -131,7 +131,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
{ {
PEFile assembly = method.ParentAssembly.PEFile; PEFile assembly = method.ParentModule.PEFile;
AddReferenceWarningMessage(assembly, output); AddReferenceWarningMessage(assembly, output);
WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true)); WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true));
CSharpDecompiler decompiler = CreateDecompiler(assembly, options); CSharpDecompiler decompiler = CreateDecompiler(assembly, options);
@ -198,7 +198,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options) public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options)
{ {
PEFile assembly = property.ParentAssembly.PEFile; PEFile assembly = property.ParentModule.PEFile;
AddReferenceWarningMessage(assembly, output); AddReferenceWarningMessage(assembly, output);
CSharpDecompiler decompiler = CreateDecompiler(assembly, options); CSharpDecompiler decompiler = CreateDecompiler(assembly, options);
WriteCommentLine(output, TypeToString(property.DeclaringType, includeNamespace: true)); WriteCommentLine(output, TypeToString(property.DeclaringType, includeNamespace: true));
@ -207,7 +207,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options) public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options)
{ {
PEFile assembly = field.ParentAssembly.PEFile; PEFile assembly = field.ParentModule.PEFile;
AddReferenceWarningMessage(assembly, output); AddReferenceWarningMessage(assembly, output);
WriteCommentLine(output, TypeToString(field.DeclaringType, includeNamespace: true)); WriteCommentLine(output, TypeToString(field.DeclaringType, includeNamespace: true));
CSharpDecompiler decompiler = CreateDecompiler(assembly, options); CSharpDecompiler decompiler = CreateDecompiler(assembly, options);
@ -266,7 +266,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileEvent(IEvent @event, ITextOutput output, DecompilationOptions options) public override void DecompileEvent(IEvent @event, ITextOutput output, DecompilationOptions options)
{ {
PEFile assembly = @event.ParentAssembly.PEFile; PEFile assembly = @event.ParentModule.PEFile;
AddReferenceWarningMessage(assembly, output); AddReferenceWarningMessage(assembly, output);
base.WriteCommentLine(output, TypeToString(@event.DeclaringType, includeNamespace: true)); base.WriteCommentLine(output, TypeToString(@event.DeclaringType, includeNamespace: true));
CSharpDecompiler decompiler = CreateDecompiler(assembly, options); CSharpDecompiler decompiler = CreateDecompiler(assembly, options);
@ -275,7 +275,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options) public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options)
{ {
PEFile assembly = type.ParentAssembly.PEFile; PEFile assembly = type.ParentModule.PEFile;
AddReferenceWarningMessage(assembly, output); AddReferenceWarningMessage(assembly, output);
WriteCommentLine(output, TypeToString(type, includeNamespace: true)); WriteCommentLine(output, TypeToString(type, includeNamespace: true));
CSharpDecompiler decompiler = CreateDecompiler(assembly, options); CSharpDecompiler decompiler = CreateDecompiler(assembly, options);
@ -331,7 +331,7 @@ namespace ICSharpCode.ILSpy
using (options.FullDecompilation ? null : LoadedAssembly.DisableAssemblyLoad()) { using (options.FullDecompilation ? null : LoadedAssembly.DisableAssemblyLoad()) {
IAssemblyResolver assemblyResolver = assembly.GetAssemblyResolver(); IAssemblyResolver assemblyResolver = assembly.GetAssemblyResolver();
var typeSystem = new DecompilerTypeSystem(module, assemblyResolver, options.DecompilerSettings); var typeSystem = new DecompilerTypeSystem(module, assemblyResolver, options.DecompilerSettings);
var globalType = typeSystem.MainAssembly.TypeDefinitions.FirstOrDefault(); var globalType = typeSystem.MainModule.TypeDefinitions.FirstOrDefault();
if (globalType != null) { if (globalType != null) {
output.Write("// Global type: "); output.Write("// Global type: ");
output.WriteReference(globalType, globalType.FullName); output.WriteReference(globalType, globalType.FullName);
@ -556,7 +556,7 @@ namespace ICSharpCode.ILSpy
public override bool ShowMember(IEntity member) 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); return showAllMembers || !CSharpDecompiler.MemberIsHidden(assembly, member.MetadataToken, new DecompilationOptions().DecompilerSettings);
} }

6
ILSpy/Languages/ILAstLanguage.cs

@ -74,7 +74,7 @@ namespace ICSharpCode.ILSpy
{ {
base.DecompileMethod(method, output, options); base.DecompileMethod(method, output, options);
new ReflectionDisassembler(output, options.CancellationToken) 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();
output.WriteLine(); output.WriteLine();
} }
@ -86,7 +86,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
{ {
base.DecompileMethod(method, output, 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); var methodDef = module.Metadata.GetMethodDefinition((SRM.MethodDefinitionHandle)method.MetadataToken);
if (!methodDef.HasBody()) if (!methodDef.HasBody())
return; return;
@ -109,7 +109,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
{ {
base.DecompileMethod(method, output, options); base.DecompileMethod(method, output, options);
var module = method.ParentAssembly.PEFile; var module = method.ParentModule.PEFile;
var metadata = module.Metadata; var metadata = module.Metadata;
var methodDef = metadata.GetMethodDefinition((SRM.MethodDefinitionHandle)method.MetadataToken); var methodDef = metadata.GetMethodDefinition((SRM.MethodDefinitionHandle)method.MetadataToken);
if (!methodDef.HasBody()) if (!methodDef.HasBody())

16
ILSpy/Languages/ILLanguage.cs

@ -63,21 +63,21 @@ namespace ICSharpCode.ILSpy
public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options) public override void DecompileMethod(IMethod method, ITextOutput output, DecompilationOptions options)
{ {
var dis = CreateDisassembler(output, options); var dis = CreateDisassembler(output, options);
dis.AssemblyResolver = method.ParentAssembly.PEFile.GetAssemblyResolver(); dis.AssemblyResolver = method.ParentModule.PEFile.GetAssemblyResolver();
dis.DisassembleMethod(method.ParentAssembly.PEFile, (MethodDefinitionHandle)method.MetadataToken); dis.DisassembleMethod(method.ParentModule.PEFile, (MethodDefinitionHandle)method.MetadataToken);
} }
public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options) public override void DecompileField(IField field, ITextOutput output, DecompilationOptions options)
{ {
var dis = CreateDisassembler(output, options); var dis = CreateDisassembler(output, options);
dis.AssemblyResolver = field.ParentAssembly.PEFile.GetAssemblyResolver(); dis.AssemblyResolver = field.ParentModule.PEFile.GetAssemblyResolver();
dis.DisassembleField(field.ParentAssembly.PEFile, (FieldDefinitionHandle)field.MetadataToken); dis.DisassembleField(field.ParentModule.PEFile, (FieldDefinitionHandle)field.MetadataToken);
} }
public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options) public override void DecompileProperty(IProperty property, ITextOutput output, DecompilationOptions options)
{ {
var dis = CreateDisassembler(output, options); var dis = CreateDisassembler(output, options);
PEFile module = property.ParentAssembly.PEFile; PEFile module = property.ParentModule.PEFile;
dis.AssemblyResolver = module.GetAssemblyResolver(); dis.AssemblyResolver = module.GetAssemblyResolver();
dis.DisassembleProperty(module, (PropertyDefinitionHandle)property.MetadataToken); dis.DisassembleProperty(module, (PropertyDefinitionHandle)property.MetadataToken);
var pd = module.Metadata.GetPropertyDefinition((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) public override void DecompileEvent(IEvent ev, ITextOutput output, DecompilationOptions options)
{ {
var dis = CreateDisassembler(output, options); var dis = CreateDisassembler(output, options);
PEFile module = ev.ParentAssembly.PEFile; PEFile module = ev.ParentModule.PEFile;
dis.AssemblyResolver = module.GetAssemblyResolver(); dis.AssemblyResolver = module.GetAssemblyResolver();
dis.DisassembleEvent(module, (EventDefinitionHandle)ev.MetadataToken); dis.DisassembleEvent(module, (EventDefinitionHandle)ev.MetadataToken);
@ -127,7 +127,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options) public override void DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options)
{ {
var dis = CreateDisassembler(output, options); var dis = CreateDisassembler(output, options);
PEFile module = type.ParentAssembly.PEFile; PEFile module = type.ParentModule.PEFile;
dis.AssemblyResolver = module.GetAssemblyResolver(); dis.AssemblyResolver = module.GetAssemblyResolver();
dis.DisassembleType(module, (TypeDefinitionHandle)type.MetadataToken); dis.DisassembleType(module, (TypeDefinitionHandle)type.MetadataToken);
} }
@ -135,7 +135,7 @@ namespace ICSharpCode.ILSpy
public override void DecompileNamespace(string nameSpace, IEnumerable<ITypeDefinition> types, ITextOutput output, DecompilationOptions options) public override void DecompileNamespace(string nameSpace, IEnumerable<ITypeDefinition> types, ITextOutput output, DecompilationOptions options)
{ {
var dis = CreateDisassembler(output, options); var dis = CreateDisassembler(output, options);
PEFile module = types.FirstOrDefault()?.ParentAssembly.PEFile; PEFile module = types.FirstOrDefault()?.ParentModule.PEFile;
dis.AssemblyResolver = module.GetAssemblyResolver(); dis.AssemblyResolver = module.GetAssemblyResolver();
dis.DisassembleNamespace(nameSpace, module, types.Select(t => (TypeDefinitionHandle)t.MetadataToken)); dis.DisassembleNamespace(nameSpace, module, types.Select(t => (TypeDefinitionHandle)t.MetadataToken));
} }

2
ILSpy/SearchPane.cs

@ -222,7 +222,7 @@ namespace ICSharpCode.ILSpy
continue; continue;
CancellationToken cancellationToken = cts.Token; CancellationToken cancellationToken = cts.Token;
foreach (var type in typeSystem.MainAssembly.TopLevelTypeDefinitions) { foreach (var type in typeSystem.MainModule.TopLevelTypeDefinitions) {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
searcher.Search(type, language, AddResult); searcher.Search(type, language, AddResult);
} }

2
ILSpy/SearchStrategies.cs

@ -321,7 +321,7 @@ namespace ICSharpCode.ILSpy
{ {
if (method == null) if (method == null)
return false; return false;
var module = ((MetadataAssembly)method.ParentAssembly).PEFile; var module = ((MetadataModule)method.ParentModule).PEFile;
var m = (SRM.MethodDefinitionHandle)method.MetadataToken; var m = (SRM.MethodDefinitionHandle)method.MetadataToken;
if (m.IsNil) if (m.IsNil)
return false; return false;

8
ILSpy/TextView/DecompilerTextView.cs

@ -211,9 +211,9 @@ namespace ICSharpCode.ILSpy.TextView
XmlDocRenderer renderer = new XmlDocRenderer(); XmlDocRenderer renderer = new XmlDocRenderer();
renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(entity)); renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(entity));
try { try {
if (entity.ParentAssembly == null || entity.ParentAssembly.PEFile == null) if (entity.ParentModule == null || entity.ParentModule.PEFile == null)
return null; return null;
var docProvider = XmlDocLoader.LoadDocumentation(entity.ParentAssembly.PEFile); var docProvider = XmlDocLoader.LoadDocumentation(entity.ParentModule.PEFile);
if (docProvider != null) { if (docProvider != null) {
string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(entity)); string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(entity));
if (documentation != null) { if (documentation != null) {
@ -237,9 +237,9 @@ namespace ICSharpCode.ILSpy.TextView
XmlDocRenderer renderer = new XmlDocRenderer(); XmlDocRenderer renderer = new XmlDocRenderer();
renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(resolved)); renderer.AppendText(MainWindow.Instance.CurrentLanguage.GetTooltip(resolved));
try { try {
if (resolved.ParentAssembly == null || resolved.ParentAssembly.PEFile == null) if (resolved.ParentModule == null || resolved.ParentModule.PEFile == null)
return null; return null;
var docProvider = XmlDocLoader.LoadDocumentation(resolved.ParentAssembly.PEFile); var docProvider = XmlDocLoader.LoadDocumentation(resolved.ParentModule.PEFile);
if (docProvider != null) { if (docProvider != null) {
string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(resolved)); string documentation = docProvider.GetDocumentation(XmlDocKeyProvider.GetKey(resolved));
if (documentation != null) { if (documentation != null) {

8
ILSpy/TreeNodes/AssemblyListTreeNode.cs

@ -177,11 +177,9 @@ namespace ICSharpCode.ILSpy.TreeNodes
return null; return null;
} }
public AssemblyTreeNode FindAssemblyNode(IAssembly module) public AssemblyTreeNode FindAssemblyNode(IModule module)
{ {
if (!(module is MetadataAssembly assembly)) return FindAssemblyNode(module.PEFile);
return null;
return FindAssemblyNode(assembly.PEFile);
} }
public AssemblyTreeNode FindAssemblyNode(PEFile module) public AssemblyTreeNode FindAssemblyNode(PEFile module)
@ -224,7 +222,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
return decl.Children.OfType<TypeTreeNode>().FirstOrDefault(t => t.TypeDefinition.MetadataToken == def.MetadataToken && !t.IsHidden); return decl.Children.OfType<TypeTreeNode>().FirstOrDefault(t => t.TypeDefinition.MetadataToken == def.MetadataToken && !t.IsHidden);
} }
} else { } else {
AssemblyTreeNode asm = FindAssemblyNode(def.ParentAssembly); AssemblyTreeNode asm = FindAssemblyNode(def.ParentModule);
if (asm != null) { if (asm != null) {
return asm.FindTypeNode(def); return asm.FindTypeNode(def);
} }

2
ILSpy/TreeNodes/AssemblyTreeNode.cs

@ -140,7 +140,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
return; return;
} }
typeSystem = LoadedAssembly.GetTypeSystemOrNull(); typeSystem = LoadedAssembly.GetTypeSystemOrNull();
var assembly = (MetadataAssembly)typeSystem.MainAssembly; var assembly = (MetadataModule)typeSystem.MainModule;
var metadata = module.Metadata; var metadata = module.Metadata;
this.Children.Add(new ReferenceFolderTreeNode(module, this)); this.Children.Add(new ReferenceFolderTreeNode(module, this));

4
ILSpy/TreeNodes/BaseTypesEntryNode.cs

@ -53,7 +53,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
var t = typeSystem.ResolveAsType(handle).GetDefinition(); var t = typeSystem.ResolveAsType(handle).GetDefinition();
if (t != null) { if (t != null) {
showExpander = t.DirectBaseTypes.Any(); showExpander = t.DirectBaseTypes.Any();
var other = t.ParentAssembly.PEFile.GetTypeSystemOrNull(); var other = t.ParentModule.PEFile.GetTypeSystemOrNull();
Debug.Assert(other != null); Debug.Assert(other != null);
t = other.FindType(t.FullTypeName).GetDefinition(); t = other.FindType(t.FullTypeName).GetDefinition();
} else { } else {
@ -74,7 +74,7 @@ namespace ICSharpCode.ILSpy.TreeNodes
{ {
var t = TryResolve(module, handle, type, false); var t = TryResolve(module, handle, type, false);
if (t != null) { if (t != null) {
BaseTypesTreeNode.AddBaseTypes(this.Children, t.ParentAssembly.PEFile, t); BaseTypesTreeNode.AddBaseTypes(this.Children, t.ParentModule.PEFile, t);
} }
} }

4
ILSpy/TreeNodes/DerivedTypesTreeNode.cs

@ -63,11 +63,11 @@ namespace ICSharpCode.ILSpy.TreeNodes
internal static IEnumerable<DerivedTypesEntryNode> FindDerivedTypes(AssemblyList list, ITypeDefinition type, internal static IEnumerable<DerivedTypesEntryNode> FindDerivedTypes(AssemblyList list, ITypeDefinition type,
PEFile[] assemblies, CancellationToken cancellationToken) PEFile[] assemblies, CancellationToken cancellationToken)
{ {
var definitionMetadata = type.ParentAssembly.PEFile.Metadata; var definitionMetadata = type.ParentModule.PEFile.Metadata;
var metadataToken = (SRM.TypeDefinitionHandle)type.MetadataToken; var metadataToken = (SRM.TypeDefinitionHandle)type.MetadataToken;
foreach (var module in assemblies) { foreach (var module in assemblies) {
var metadata = module.Metadata; var metadata = module.Metadata;
var assembly = (MetadataAssembly)module.GetTypeSystemOrNull().MainAssembly; var assembly = (MetadataModule)module.GetTypeSystemOrNull().MainModule;
foreach (var h in metadata.TypeDefinitions) { foreach (var h in metadata.TypeDefinitions) {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var td = metadata.GetTypeDefinition(h); var td = metadata.GetTypeDefinition(h);

2
ILSpy/TypeExtensionMethodsAnalyzer.cs

@ -25,7 +25,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
var firstParamType = method.Parameters[0].Type.GetDefinition(); var firstParamType = method.Parameters[0].Type.GetDefinition();
if (firstParamType != null && if (firstParamType != null &&
firstParamType.MetadataToken == analyzedType.MetadataToken && firstParamType.MetadataToken == analyzedType.MetadataToken &&
firstParamType.ParentAssembly.PEFile == analyzedType.ParentAssembly.PEFile) firstParamType.ParentModule.PEFile == analyzedType.ParentModule.PEFile)
yield return method; yield return method;
} }
} }

2
TestPlugin/CustomLanguage.cs

@ -33,7 +33,7 @@ namespace TestPlugin
// There are several methods available to override; in this sample, we deal with methods only // 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) 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); var methodDef = module.Metadata.GetMethodDefinition((MethodDefinitionHandle)method.MetadataToken);
if (methodDef.HasBody()) { if (methodDef.HasBody()) {
var methodBody = module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress); var methodBody = module.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);

Loading…
Cancel
Save