зеркало из https://github.com/mono/ikvm-fork.git
160 строки
4.2 KiB
C#
160 строки
4.2 KiB
C#
/*
|
|
Copyright (C) 2009 Jeroen Frijters
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
warranty. In no event will the authors be held liable for any damages
|
|
arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
including commercial applications, and to alter it and redistribute it
|
|
freely, subject to the following restrictions:
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
claim that you wrote the original software. If you use this software
|
|
in a product, an acknowledgment in the product documentation would be
|
|
appreciated but is not required.
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
misrepresented as being the original software.
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
Jeroen Frijters
|
|
jeroen@frijters.net
|
|
|
|
*/
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace IKVM.Reflection
|
|
{
|
|
public abstract class Assembly : ICustomAttributeProvider
|
|
{
|
|
internal readonly Universe universe;
|
|
|
|
internal Assembly(Universe universe)
|
|
{
|
|
this.universe = universe;
|
|
}
|
|
|
|
public abstract Type[] GetTypes();
|
|
public abstract string FullName { get; }
|
|
public abstract AssemblyName GetName();
|
|
public abstract string ImageRuntimeVersion { get; }
|
|
public abstract Module ManifestModule { get; }
|
|
public abstract MethodInfo EntryPoint { get; }
|
|
public abstract string Location { get; }
|
|
public abstract AssemblyName[] GetReferencedAssemblies();
|
|
public abstract Module[] GetModules(bool getResourceModules);
|
|
public abstract Module[] GetLoadedModules(bool getResourceModules);
|
|
public abstract Module GetModule(string name);
|
|
public abstract string[] GetManifestResourceNames();
|
|
public abstract ManifestResourceInfo GetManifestResourceInfo(string resourceName);
|
|
public abstract System.IO.Stream GetManifestResourceStream(string resourceName);
|
|
|
|
internal abstract Type GetTypeImpl(string typeName);
|
|
|
|
public Module[] GetModules()
|
|
{
|
|
return GetModules(true);
|
|
}
|
|
|
|
public Module[] GetLoadedModules()
|
|
{
|
|
return GetLoadedModules(true);
|
|
}
|
|
|
|
public AssemblyName GetName(bool copiedName)
|
|
{
|
|
return GetName();
|
|
}
|
|
|
|
public bool ReflectionOnly
|
|
{
|
|
get { return true; }
|
|
}
|
|
|
|
public Type[] GetExportedTypes()
|
|
{
|
|
List<Type> list = new List<Type>();
|
|
foreach (Type type in GetTypes())
|
|
{
|
|
if (type.IsVisible)
|
|
{
|
|
list.Add(type);
|
|
}
|
|
}
|
|
return list.ToArray();
|
|
}
|
|
|
|
public Type GetType(string typeName)
|
|
{
|
|
return GetType(typeName, false);
|
|
}
|
|
|
|
public Type GetType(string typeName, bool throwOnError)
|
|
{
|
|
TypeNameParser parser = TypeNameParser.Parse(typeName, throwOnError);
|
|
if (parser.Error)
|
|
{
|
|
return null;
|
|
}
|
|
if (parser.AssemblyName != null)
|
|
{
|
|
if (throwOnError)
|
|
{
|
|
throw new ArgumentException("Type names passed to Assembly.GetType() must not specify an assembly.");
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
return parser.Expand(GetTypeImpl(parser.FirstNamePart), this, throwOnError, typeName);
|
|
}
|
|
|
|
public virtual Module LoadModule(string moduleName, byte[] rawModule)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
|
|
public Module LoadModule(string moduleName, byte[] rawModule, byte[] rawSymbolStore)
|
|
{
|
|
return LoadModule(moduleName, rawModule);
|
|
}
|
|
|
|
public bool IsDefined(Type attributeType, bool inherit)
|
|
{
|
|
return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit).Count != 0;
|
|
}
|
|
|
|
public IList<CustomAttributeData> __GetCustomAttributes(Type attributeType, bool inherit)
|
|
{
|
|
return CustomAttributeData.__GetCustomAttributes(this, attributeType, inherit);
|
|
}
|
|
|
|
public static string CreateQualifiedName(string assemblyName, string typeName)
|
|
{
|
|
return assemblyName == null ? typeName : typeName + ", " + assemblyName;
|
|
}
|
|
|
|
public static Assembly GetAssembly(Type type)
|
|
{
|
|
return type.Assembly;
|
|
}
|
|
|
|
public string CodeBase
|
|
{
|
|
get
|
|
{
|
|
string path = this.Location.Replace(System.IO.Path.DirectorySeparatorChar, '/');
|
|
if (!path.StartsWith("/"))
|
|
{
|
|
path = "/" + path;
|
|
}
|
|
return "file://" + path;
|
|
}
|
|
}
|
|
|
|
internal abstract IList<CustomAttributeData> GetCustomAttributesData(Type attributeType);
|
|
}
|
|
}
|