IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
IkvmReflectionAssemblySymbol.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Collections.Immutable;
4using System.Diagnostics;
6
11
13{
14
16 {
17
18 readonly Assembly _underlyingAssembly;
19 readonly ConditionalWeakTable<Module, IkvmReflectionModuleSymbol> _modules = new();
20
21 global::System.Reflection.AssemblyName? _assemblyName;
22 ImmutableArray<CustomAttributeSymbol> _customAttributes = default;
23
30 base(context)
31 {
32 _underlyingAssembly = underlyingAssembly ?? throw new ArgumentNullException(nameof(underlyingAssembly));
33 }
34
41 internal IkvmReflectionModuleSymbol GetOrCreateModuleSymbol(Module module)
42 {
43 Debug.Assert(module.Assembly == _underlyingAssembly);
44 return _modules.GetValue(module, _ => new IkvmReflectionModuleSymbol(Context, _));
45 }
46
47 internal Assembly UnderlyingAssembly => _underlyingAssembly;
48
49 public string? FullName => _underlyingAssembly.FullName;
50
51 public IModuleSymbol ManifestModule => ResolveModuleSymbol(_underlyingAssembly.ManifestModule);
52
53 public IEnumerable<IModuleSymbol> Modules => ResolveModuleSymbols(_underlyingAssembly.Modules);
54
55 public IEnumerable<ITypeSymbol> DefinedTypes => ResolveTypeSymbols(_underlyingAssembly.DefinedTypes);
56
57 public IEnumerable<ITypeSymbol> ExportedTypes => ResolveTypeSymbols(_underlyingAssembly.ExportedTypes);
58
59 public IMethodSymbol? EntryPoint => _underlyingAssembly.EntryPoint is { } m ? ResolveMethodSymbol(m) : null;
60
61 public override bool IsMissing => _underlyingAssembly.__IsMissing;
62
64 {
65 return ResolveTypeSymbols(_underlyingAssembly.GetExportedTypes());
66 }
67
68 public IModuleSymbol? GetModule(string name)
69 {
70 return _underlyingAssembly.GetModule(name) is Module m ? GetOrCreateModuleSymbol(m) : null;
71 }
72
73 public ImmutableArray<IModuleSymbol> GetModules()
74 {
75 return ResolveModuleSymbols(_underlyingAssembly.GetModules()).CastArray<IModuleSymbol>();
76 }
77
78 public ImmutableArray<IModuleSymbol> GetModules(bool getResourceModules)
79 {
80 return ResolveModuleSymbols(_underlyingAssembly.GetModules(getResourceModules)).CastArray<IModuleSymbol>();
81 }
82
83 global::System.Reflection.AssemblyName ToName(AssemblyName src)
84 {
85#pragma warning disable SYSLIB0037 // Type or member is obsolete
86 return new global::System.Reflection.AssemblyName()
87 {
88 Name = src.Name,
89 Version = src.Version,
90 CultureName = src.CultureName,
91 HashAlgorithm = (global::System.Configuration.Assemblies.AssemblyHashAlgorithm)src.HashAlgorithm,
92 Flags = (global::System.Reflection.AssemblyNameFlags)src.Flags,
93 ContentType = (global::System.Reflection.AssemblyContentType)src.ContentType,
94 };
95#pragma warning restore SYSLIB0037 // Type or member is obsolete
96 }
97
98 public global::System.Reflection.AssemblyName GetName()
99 {
100 return _assemblyName ??= ToName(_underlyingAssembly.GetName());
101 }
102
103 public ImmutableArray<global::System.Reflection.AssemblyName> GetReferencedAssemblies()
104 {
105 var l = _underlyingAssembly.GetReferencedAssemblies().ToImmutableArray();
106 var a = ImmutableArray.CreateBuilder<global::System.Reflection.AssemblyName>(l.Length);
107 for (int i = 0; i < l.Length; i++)
108 a.Add(ToName(l[i]));
109
110 return a.DrainToImmutable();
111 }
112
113 public ITypeSymbol? GetType(string name)
114 {
115 return _underlyingAssembly.GetType(name) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
116 }
117
118 public ITypeSymbol? GetType(string name, bool throwOnError)
119 {
120 return _underlyingAssembly.GetType(name, throwOnError) is Type t ? Context.GetOrCreateTypeSymbol(t) : null;
121 }
122
124 {
125 return ResolveTypeSymbols(_underlyingAssembly.GetTypes());
126 }
127
128 public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes()
129 {
130 return _customAttributes.IsDefault ? _customAttributes = ResolveCustomAttributes(_underlyingAssembly.GetCustomAttributesData()) : _customAttributes;
131 }
132
133 public ImmutableArray<CustomAttributeSymbol> GetCustomAttributes(ITypeSymbol attributeType)
134 {
135 return ResolveCustomAttributes(_underlyingAssembly.__GetCustomAttributes(((IkvmReflectionTypeSymbol)attributeType).UnderlyingType, false));
136 }
137
138 public bool IsDefined(ITypeSymbol attributeType)
139 {
140 return _underlyingAssembly.IsDefined(((IkvmReflectionTypeSymbol)attributeType).UnderlyingType, false);
141 }
142
143 }
144
145}
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.Assembly Assembly
IKVM.Reflection.AssemblyName AssemblyName
global::java.lang.invoke.LambdaForm.Name Name
ImmutableArray< IModuleSymbol > GetModules(bool getResourceModules)
Gets all the modules that are part of this assembly, specifying whether to include resource modules.
ImmutableArray< global::System.Reflection.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.
IMethodSymbol? EntryPoint
Gets the entry point of this assembly.
ImmutableArray< IModuleSymbol > GetModules()
Gets all the modules that are part of this assembly.
bool IsDefined(ITypeSymbol attributeType)
Indicates whether one or more instance of attributeType is defined on this member.
ITypeSymbol? GetType(string name)
Gets the ITypeSymbol object with the specified name in the assembly instance.
ITypeSymbol? GetType(string name, bool throwOnError)
Gets the ITypeSymbol object with the specified name in the assembly instance and optionally throws an...
IModuleSymbol ManifestModule
Gets the module that contains the manifest for the current assembly.
ImmutableArray< CustomAttributeSymbol > GetCustomAttributes(ITypeSymbol attributeType)
Returns an array of custom attributes defined on this member, identified by type, or an empty array i...
override bool IsMissing
Returns true if the symbol is missing.
IEnumerable< IModuleSymbol > Modules
Gets a collection that contains the modules in this assembly.
ITypeSymbol[] GetTypes()
Gets all types defined in this assembly.
IModuleSymbol? GetModule(string name)
Gets the specified module in this assembly.
ImmutableArray< CustomAttributeSymbol > GetCustomAttributes()
Returns an array of all of the custom attributes defined on this member, excluding named attributes,...
global::System.Reflection.AssemblyName GetName()
Gets an AssemblyName for this assembly.
ITypeSymbol[] GetExportedTypes()
Gets the public types defined in this assembly that are visible outside the assembly.
IkvmReflectionAssemblySymbol(IkvmReflectionSymbolContext context, Assembly underlyingAssembly)
Initializes a new instance.
IEnumerable< ITypeSymbol > ExportedTypes
Gets a collection of the public types defined in this assembly that are visible outside the assembly.
Implementation of IModuleSymbol derived from System.Reflection.
Holds references to symbols derived from System.Reflection.
IkvmReflectionTypeSymbol GetOrCreateTypeSymbol(Type type)
Gets or creates a IkvmReflectionTypeSymbol for the specified Type.
IkvmReflectionSymbolContext Context
Gets the associated IkvmReflectionSymbolContext.
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,...