IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
ReflectionAssemblySymbol.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Collections.Immutable;
4using System.Diagnostics;
5using System.Linq;
6using System.Reflection;
8
10{
11
13 {
14
15 readonly Assembly _underlyingAssembly;
16 readonly ConditionalWeakTable<Module, ReflectionModuleSymbol> _modules = new();
17
18 ImmutableArray<CustomAttributeSymbol> _customAttributes = default;
19
25 public ReflectionAssemblySymbol(ReflectionSymbolContext context, Assembly underlyingAssembly) :
26 base(context)
27 {
28 _underlyingAssembly = underlyingAssembly ?? throw new ArgumentNullException(nameof(underlyingAssembly));
29 }
30
31 internal Assembly UnderlyingAssembly => _underlyingAssembly;
32
39 internal ReflectionModuleSymbol GetOrCreateModuleSymbol(Module module)
40 {
41 Debug.Assert(module.Assembly == _underlyingAssembly);
42 return _modules.GetValue(module, _ => new ReflectionModuleSymbol(Context, _));
43 }
44
45 public IEnumerable<ITypeSymbol> DefinedTypes => ResolveTypeSymbols(_underlyingAssembly.DefinedTypes);
46
47 public IMethodSymbol? EntryPoint => _underlyingAssembly.EntryPoint is { } m ? ResolveMethodSymbol(m) : null;
48
49 public IEnumerable<ITypeSymbol> ExportedTypes => ResolveTypeSymbols(_underlyingAssembly.ExportedTypes);
50
51 public string? FullName => _underlyingAssembly.FullName;
52
53 public IModuleSymbol ManifestModule => ResolveModuleSymbol(_underlyingAssembly.ManifestModule);
54
55 public IEnumerable<IModuleSymbol> Modules => ResolveModuleSymbols(_underlyingAssembly.Modules);
56
58 {
59 return ResolveTypeSymbols(_underlyingAssembly.GetExportedTypes());
60 }
61
62 public IModuleSymbol? GetModule(string name)
63 {
64 return _underlyingAssembly.GetModule(name) is Module m ? GetOrCreateModuleSymbol(m) : null;
65 }
66
67 public ImmutableArray<IModuleSymbol> GetModules()
68 {
69 return ResolveModuleSymbols(_underlyingAssembly.GetModules()).CastArray<IModuleSymbol>();
70 }
71
72 public ImmutableArray<IModuleSymbol> GetModules(bool getResourceModules)
73 {
74 return ResolveModuleSymbols(_underlyingAssembly.GetModules(getResourceModules)).CastArray<IModuleSymbol>();
75 }
76
78 {
79 return _underlyingAssembly.GetName();
80 }
81
82 public ImmutableArray<AssemblyName> GetReferencedAssemblies()
83 {
84 return _underlyingAssembly.GetReferencedAssemblies().ToImmutableArray();
85 }
86
87 public ITypeSymbol? GetType(string name)
88 {
89 return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
90 }
91
92 public ITypeSymbol? GetType(string name, bool throwOnError)
93 {
94 return _underlyingAssembly.GetType(name, throwOnError) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
95 }
96
98 {
99 return ResolveTypeSymbols(_underlyingAssembly.GetTypes());
100 }
101
102 public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes()
103 {
104 return _customAttributes.IsDefault ? _customAttributes = ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData()) : _customAttributes;
105 }
106
107 public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes(ITypeSymbol attributeType)
108 {
109 return GetCustomAttributes().Where(i => i.AttributeType == attributeType).ToImmutableArray();
110 }
111
112 public bool IsDefined(ITypeSymbol attributeType)
113 {
114 return _underlyingAssembly.IsDefined(((ReflectionTypeSymbol)attributeType).UnderlyingType);
115 }
116
117 }
118
119}
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.Assembly Assembly
IKVM.Reflection.AssemblyName AssemblyName
IModuleSymbol? GetModule(string name)
Gets the specified module in this assembly.
ITypeSymbol[] GetTypes()
Gets all types defined in this assembly.
bool IsDefined(ITypeSymbol attributeType)
Indicates whether one or more instance of attributeType is defined on this member.
ITypeSymbol? GetType(string name, bool throwOnError)
Gets the ITypeSymbol object with the specified name in the assembly instance and optionally throws an...
IEnumerable< ITypeSymbol > ExportedTypes
Gets a collection of the public types defined in this assembly that are visible outside the assembly.
ImmutableArray< IModuleSymbol > GetModules(bool getResourceModules)
Gets all the modules that are part of this assembly, specifying whether to include resource modules.
ImmutableArray< CustomAttributeSymbol > GetCustomAttributes()
Returns an array of all of the custom attributes defined on this member, excluding named attributes,...
string? FullName
Gets the display name of the assembly.
AssemblyName GetName()
Gets an AssemblyName for this assembly.
IModuleSymbol ManifestModule
Gets the module that contains the manifest for the current assembly.
ImmutableArray< IModuleSymbol > GetModules()
Gets all the modules that are part of this assembly.
ITypeSymbol? GetType(string name)
Gets the ITypeSymbol object with the specified name in the assembly instance.
IEnumerable< IModuleSymbol > Modules
Gets a collection that contains the modules in this assembly.
ReflectionAssemblySymbol(ReflectionSymbolContext context, Assembly underlyingAssembly)
Initializes a new instance.
IMethodSymbol? EntryPoint
Gets the entry point of this assembly.
ImmutableArray< AssemblyName > GetReferencedAssemblies()
Gets the AssemblyName objects for all the assemblies referenced by this assembly.
IEnumerable< ITypeSymbol > DefinedTypes
Gets a collection of the types defined in this assembly.
ITypeSymbol[] GetExportedTypes()
Gets the public types defined in this assembly that are visible outside the assembly.
ImmutableArray< CustomAttributeSymbol > GetCustomAttributes(ITypeSymbol attributeType)
Returns an array of custom attributes defined on this member, identified by type, or an empty array i...
Implementation of IModuleSymbol derived from System.Reflection.
Holds references to symbols derived from System.Reflection.
ReflectionTypeSymbol GetOrCreateTypeSymbol(Type type)
Gets or creates a ReflectionTypeSymbol for the specified Type.
ReflectionSymbolContext Context
Gets the associated ReflectionSymbolContext.
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Discovers the attributes of a method and provides access to method metadata.
Performs reflection on a module.
Represents type declarations: class types, interface types, array types, value types,...