2
Copyright (C) 2009-2012 Jeroen Frijters
4
This software is provided 'as-is', without any express or implied
5
warranty. In no event will the authors be held liable for any damages
6
arising from the use of this software.
8
Permission is granted to anyone to use this software for any purpose,
9
including commercial applications, and to alter it and redistribute it
10
freely, subject to the following restrictions:
12
1. The origin of this software must not be misrepresented; you must not
13
claim that you wrote the original software. If you use this software
14
in a product, an acknowledgment in the product documentation would be
15
appreciated but is not required.
16
2. Altered source versions must be plainly marked as such, and must not be
17
misrepresented as being the original software.
18
3. This notice may not be removed or altered from any source distribution.
25
using System.Collections.Generic;
27
namespace IKVM.Reflection
29
public delegate Module ModuleResolveEventHandler(object sender, ResolveEventArgs e);
31
public abstract class Assembly : ICustomAttributeProvider
33
internal readonly Universe universe;
34
protected string fullName; // AssemblyBuilder needs access to this field to clear it when the name changes
35
protected List<ModuleResolveEventHandler> resolvers;
37
internal Assembly(Universe universe)
39
this.universe = universe;
42
public sealed override string ToString()
47
public event ModuleResolveEventHandler ModuleResolve
51
if (resolvers == null)
53
resolvers = new List<ModuleResolveEventHandler>();
59
resolvers.Remove(value);
63
public abstract Type[] GetTypes();
64
public abstract AssemblyName GetName();
65
public abstract string ImageRuntimeVersion { get; }
66
public abstract Module ManifestModule { get; }
67
public abstract MethodInfo EntryPoint { get; }
68
public abstract string Location { get; }
69
public abstract AssemblyName[] GetReferencedAssemblies();
70
public abstract Module[] GetModules(bool getResourceModules);
71
public abstract Module[] GetLoadedModules(bool getResourceModules);
72
public abstract Module GetModule(string name);
73
public abstract string[] GetManifestResourceNames();
74
public abstract ManifestResourceInfo GetManifestResourceInfo(string resourceName);
75
public abstract System.IO.Stream GetManifestResourceStream(string name);
77
internal abstract Type FindType(TypeName name);
78
internal abstract Type FindTypeIgnoreCase(TypeName lowerCaseName);
80
// The differences between ResolveType and FindType are:
81
// - ResolveType is only used when a type is assumed to exist (because another module's metadata claims it)
82
// - ResolveType can return a MissingType
83
internal Type ResolveType(TypeName typeName)
85
return FindType(typeName) ?? universe.GetMissingTypeOrThrow(this.ManifestModule, null, typeName);
88
public string FullName
90
get { return fullName ?? (fullName = GetName().FullName); }
93
public Module[] GetModules()
95
return GetModules(true);
98
public IEnumerable<Module> Modules
100
get { return GetLoadedModules(); }
103
public Module[] GetLoadedModules()
105
return GetLoadedModules(true);
108
public AssemblyName GetName(bool copiedName)
113
public bool ReflectionOnly
118
public Type[] GetExportedTypes()
120
List<Type> list = new List<Type>();
121
foreach (Type type in GetTypes())
128
return list.ToArray();
131
public IEnumerable<Type> ExportedTypes
133
get { return GetExportedTypes(); }
136
public IEnumerable<TypeInfo> DefinedTypes
140
Type[] types = GetTypes();
141
TypeInfo[] typeInfos = new TypeInfo[types.Length];
142
for (int i = 0; i < types.Length; i++)
144
typeInfos[i] = types[i].GetTypeInfo();
150
public Type GetType(string name)
152
return GetType(name, false);
155
public Type GetType(string name, bool throwOnError)
157
return GetType(name, throwOnError, false);
160
public Type GetType(string name, bool throwOnError, bool ignoreCase)
162
TypeNameParser parser = TypeNameParser.Parse(name, throwOnError);
167
if (parser.AssemblyName != null)
171
throw new ArgumentException("Type names passed to Assembly.GetType() must not specify an assembly.");
178
TypeName typeName = TypeName.Split(TypeNameParser.Unescape(parser.FirstNamePart));
179
Type type = ignoreCase
180
? FindTypeIgnoreCase(typeName.ToLowerInvariant())
181
: FindType(typeName);
182
if (type == null && __IsMissing)
184
throw new MissingAssemblyException((MissingAssembly)this);
186
return parser.Expand(type, this, throwOnError, name, false, ignoreCase);
189
public virtual Module LoadModule(string moduleName, byte[] rawModule)
191
throw new NotSupportedException();
194
public Module LoadModule(string moduleName, byte[] rawModule, byte[] rawSymbolStore)
196
return LoadModule(moduleName, rawModule);
199
public bool IsDefined(Type attributeType, bool inherit)
201
return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
204
public IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
206
return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
209
public IList<CustomAttributeData> GetCustomAttributesData()
211
return CustomAttributeData.GetCustomAttributes(this);
214
public IEnumerable<CustomAttributeData> CustomAttributes
216
get { return GetCustomAttributesData(); }
219
public static string CreateQualifiedName(string assemblyName, string typeName)
221
return typeName + ", " + assemblyName;
224
public static Assembly GetAssembly(Type type)
226
return type.Assembly;
229
public string CodeBase
233
string path = this.Location.Replace(System.IO.Path.DirectorySeparatorChar, '/');
234
if (!path.StartsWith("/"))
238
return "file://" + path;
242
public virtual bool IsDynamic
244
get { return false; }
247
public virtual bool __IsMissing
249
get { return false; }
252
public AssemblyNameFlags __AssemblyFlags
254
get { return GetAssemblyFlags(); }
257
protected virtual AssemblyNameFlags GetAssemblyFlags()
259
return GetName().Flags;
262
internal abstract IList<CustomAttributeData> GetCustomAttributesData(Type attributeType);