25using System.Collections.Generic;
31 internal abstract class Assembly : ICustomAttributeProvider
34 readonly Universe universe;
35 protected string fullName;
36 protected List<ModuleResolveEventHandler> resolvers;
44 this.universe = universe ??
throw new ArgumentNullException(nameof(universe));
50 public Universe Universe => universe;
52 public sealed override string ToString()
57 public event ModuleResolveEventHandler ModuleResolve
61 resolvers ??=
new List<ModuleResolveEventHandler>();
66 resolvers.Remove(value);
70 public abstract Type[] GetTypes();
74 public abstract string ImageRuntimeVersion {
get; }
76 public abstract Module ManifestModule {
get; }
78 public abstract string Location {
get; }
79 public abstract AssemblyName[] GetReferencedAssemblies();
80 public abstract Module[] GetModules(
bool getResourceModules);
81 public abstract Module[] GetLoadedModules(
bool getResourceModules);
82 public abstract Module GetModule(
string name);
83 public abstract string[] GetManifestResourceNames();
84 public abstract ManifestResourceInfo GetManifestResourceInfo(
string resourceName);
85 public abstract System.IO.Stream GetManifestResourceStream(
string name);
87 public virtual System.IO.Stream GetManifestResourceStream(
Type type,
string name)
89 var sb =
new StringBuilder();
92 throw new ArgumentNullException(nameof(type));
96 string? nameSpace = type.Namespace;
97 if (nameSpace !=
null)
102 sb.Append(
System.Type.Delimiter);
112 return GetManifestResourceStream(sb.ToString());
115 internal abstract Type FindType(TypeName name);
116 internal abstract Type FindTypeIgnoreCase(TypeName lowerCaseName);
121 internal Type ResolveType(
Module requester, TypeName typeName)
123 return FindType(typeName) ?? universe.GetMissingTypeOrThrow(requester, this.ManifestModule,
null, typeName);
126 public string FullName
128 get {
return fullName ??= GetName().FullName; }
131 public Module[] GetModules()
133 return GetModules(
true);
136 public IEnumerable<Module> Modules
138 get {
return GetLoadedModules(); }
141 public Module[] GetLoadedModules()
143 return GetLoadedModules(
true);
151 public bool ReflectionOnly
156 public Type[] GetExportedTypes()
158 var list =
new List<Type>();
159 foreach (var type
in GetTypes())
163 return list.ToArray();
166 public IEnumerable<Type> ExportedTypes
168 get {
return GetExportedTypes(); }
171 public IEnumerable<TypeInfo> DefinedTypes
175 var types = GetTypes();
176 var typeInfos =
new TypeInfo[types.Length];
177 for (
int i = 0; i < types.Length; i++)
178 typeInfos[i] = types[i].GetTypeInfo();
184 public Type GetType(
string name)
186 return GetType(name,
false);
189 public Type GetType(
string name,
bool throwOnError)
191 return GetType(name, throwOnError,
false);
194 public Type GetType(
string name,
bool throwOnError,
bool ignoreCase)
196 var parser = TypeNameParser.Parse(name, throwOnError);
200 if (parser.AssemblyName !=
null)
203 throw new ArgumentException(
"Type names passed to Assembly.GetType() must not specify an assembly.");
208 var typeName = TypeName.Split(TypeNameParser.Unescape(parser.FirstNamePart));
209 var type = ignoreCase ? FindTypeIgnoreCase(typeName.ToLowerInvariant()) : FindType(typeName);
210 if (type ==
null && __IsMissing)
211 throw new MissingAssemblyException((MissingAssembly)
this);
213 return parser.Expand(type, this.ManifestModule, throwOnError, name,
false, ignoreCase);
216 public virtual Module LoadModule(
string moduleName,
byte[] rawModule)
218 throw new NotSupportedException();
221 public Module LoadModule(
string moduleName,
byte[] rawModule,
byte[] rawSymbolStore)
223 return LoadModule(moduleName, rawModule);
226 public bool IsDefined(
Type attributeType,
bool inherit)
228 return CustomAttributeData.__GetCustomAttributes(
this, attributeType, inherit).Count != 0;
231 public IList<CustomAttributeData> __GetCustomAttributes(
Type attributeType,
bool inherit)
233 return CustomAttributeData.__GetCustomAttributes(
this, attributeType, inherit);
236 public IList<CustomAttributeData> GetCustomAttributesData()
238 return CustomAttributeData.GetCustomAttributes(
this);
241 public IEnumerable<CustomAttributeData> CustomAttributes
243 get {
return GetCustomAttributesData(); }
246 public static string CreateQualifiedName(
string assemblyName,
string typeName)
248 return typeName +
", " + assemblyName;
253 return type.Assembly;
256 public string CodeBase
260 var path = this.Location.Replace(
System.IO.Path.DirectorySeparatorChar,
'/');
261 if (path.StartsWith(
"/") ==
false)
264 return "file://" + path;
268 public virtual bool IsDynamic =>
false;
270 public virtual bool __IsMissing =>
false;
272 public AssemblyNameFlags __AssemblyFlags => GetAssemblyFlags();
274 protected virtual AssemblyNameFlags GetAssemblyFlags()
276 return GetName().Flags;
279 internal abstract IList<CustomAttributeData> GetCustomAttributesData(
Type attributeType);
IKVM.Reflection.Module Module
IKVM.Reflection.Type Type
IKVM.Reflection.Assembly Assembly
IKVM.Reflection.AssemblyName AssemblyName
IKVM.Reflection.MethodInfo MethodInfo