Files
mono/mcs/class/corlib/System.Reflection/Assembly.cs
T
Paolo Molaro 3c310c3846 Mon Nov 18 17:52:56 CET 2002 Paolo Molaro <[email protected]>
* Assembly.cs: implemented GetManifestResourceStream (Type type,
	* String name).

svn path=/trunk/mcs/; revision=9060
2002-11-18 16:56:38 +00:00

343 lines
8.7 KiB
C#

//
// System.Reflection/Assembly.cs
//
// Author:
// Paolo Molaro ([email protected])
//
// (C) 2001 Ximian, Inc. http://www.ximian.com
//
using System;
using System.Security.Policy;
using System.Runtime.Serialization;
using System.Reflection.Emit;
using System.IO;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace System.Reflection {
[Serializable]
public class Assembly : System.Reflection.ICustomAttributeProvider,
System.Security.IEvidenceFactory, System.Runtime.Serialization.ISerializable {
private IntPtr _mono_assembly;
internal Assembly () {}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern string get_code_base ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern string get_location ();
public virtual string CodeBase {
get {
return get_code_base ();
}
}
internal virtual string CopiedCodeBase {
get {
return get_code_base ();
}
}
public virtual string FullName {
get {
//
// FIXME: This is wrong, but it gets us going
// in the compiler for now
//
return GetName (false).ToString ();
}
}
public virtual extern MethodInfo EntryPoint {
[MethodImplAttribute (MethodImplOptions.InternalCall)]
get;
}
public virtual Evidence Evidence {
get {
return null;
}
}
public virtual String Location {
get {
return get_location ();
}
}
public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
{
}
public virtual bool IsDefined (Type attributeType, bool inherit)
{
return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
}
public virtual object [] GetCustomAttributes (bool inherit)
{
return MonoCustomAttrs.GetCustomAttributes (this, inherit);
}
public virtual object [] GetCustomAttributes (Type attributeType, bool inherit)
{
return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern object GetFilesInternal (String name);
public virtual FileStream[] GetFiles ()
{
string[] names = (string[])GetFilesInternal (null);
FileStream[] res = new FileStream [names.Length];
for (int i = 0; i < names.Length; ++i)
res [i] = new FileStream (names [i], FileMode.Open, FileAccess.Read);
return res;
}
public virtual FileStream GetFile (String name)
{
if (name == null)
throw new ArgumentNullException ("name");
string filename = (string)GetFilesInternal (name);
if (filename != null)
return new FileStream (filename, FileMode.Open, FileAccess.Read);
else
return null;
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern object GetManifestResourceInternal (String name);
public virtual Stream GetManifestResourceStream (String name)
{
if (name == null)
throw new ArgumentNullException ("name");
object data = GetManifestResourceInternal (name);
string filename = data as string;
if (data == null)
return null;
if (filename != null) {
return new FileStream (filename, FileMode.Open, FileAccess.Read);
} else {
return new MemoryStream ((byte[])data, false);
}
}
public virtual Stream GetManifestResourceStream (Type type, String name)
{
if (type == null)
throw new ArgumentNullException ("type");
string ns = type.Namespace;
if (ns == null)
return GetManifestResourceStream (name);
else
return GetManifestResourceStream (ns + "." + name);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
private extern Type[] GetTypes (bool exportedOnly);
public virtual Type[] GetTypes ()
{
return GetTypes (false);
}
public virtual Type[] GetExportedTypes ()
{
return GetTypes (true);
}
public virtual Type GetType (String name, Boolean throwOnError)
{
return GetType (name, throwOnError, false);
}
public virtual Type GetType (String name) {
return GetType (name, false, false);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
extern Type InternalGetType (String name, Boolean throwOnError, Boolean ignoreCase);
public Type GetType (string name, bool throwOnError, bool ignoreCase)
{
if (name == null)
throw new ArgumentNullException (name);
return InternalGetType (name, throwOnError, ignoreCase);
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
static extern void FillName (Assembly ass, AssemblyName aname);
public virtual AssemblyName GetName (Boolean copiedName)
{
AssemblyName aname = new AssemblyName ();
FillName (this, aname);
return aname;
}
public virtual AssemblyName GetName ()
{
return GetName (false);
}
public override String ToString ()
{
return GetName ().Name;
}
[MonoTODO]
public static String CreateQualifiedName (String assemblyName, String typeName)
{
return typeName + "," + assemblyName;
}
public static Assembly GetAssembly (Type type)
{
if (type != null)
return type.Assembly;
throw new ArgumentNullException ("type");
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public static extern Assembly GetEntryAssembly();
[MonoTODO]
public Assembly GetSatelliteAssembly (CultureInfo culture)
{
throw new NotImplementedException ();
}
[MonoTODO]
public Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
{
throw new NotImplementedException ();
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static Assembly LoadFrom (String assemblyFile);
public static Assembly Load (String assemblyString)
{
return AppDomain.CurrentDomain.Load (assemblyString);
}
public static Assembly Load (String assemblyString, Evidence assemblySecurity)
{
return AppDomain.CurrentDomain.Load (assemblyString, assemblySecurity);
}
public static Assembly Load (AssemblyName assemblyRef)
{
return AppDomain.CurrentDomain.Load (assemblyRef);
}
public static Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
{
return AppDomain.CurrentDomain.Load (assemblyRef, assemblySecurity);
}
public static Assembly Load (Byte[] rawAssembly)
{
return AppDomain.CurrentDomain.Load (rawAssembly);
}
public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore)
{
return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore);
}
public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore,
Evidence securityEvidence)
{
return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore, securityEvidence);
}
public static Assembly LoadWithPartialName (string partialName)
{
return LoadWithPartialName (partialName, null);
}
[MonoTODO]
public static Assembly LoadWithPartialName (string partialName, Evidence securityEvidence)
{
return AppDomain.CurrentDomain.Load (partialName, securityEvidence);
}
public Object CreateInstance (String typeName)
{
return CreateInstance (typeName, false);
}
public Object CreateInstance (String typeName, Boolean ignoreCase)
{
Type t = GetType (typeName, true, ignoreCase);
return Activator.CreateInstance (t);
}
public Object CreateInstance (String typeName, Boolean ignoreCase,
BindingFlags bindingAttr, Binder binder,
Object[] args, CultureInfo culture,
Object[] activationAttributes)
{
Type t = GetType (typeName, true, ignoreCase);
return Activator.CreateInstance (t, bindingAttr, binder, args, culture, activationAttributes);
}
public Module[] GetLoadedModules ()
{
throw new NotImplementedException ();
}
public Module[] GetModules ()
{
throw new NotImplementedException ();
}
public Module GetModule (String name)
{
throw new NotImplementedException ();
}
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern virtual String[] GetManifestResourceNames ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static Assembly GetExecutingAssembly ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern static Assembly GetCallingAssembly ();
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern AssemblyName[] GetReferencedAssemblies ();
public virtual ManifestResourceInfo GetManifestResourceInfo (String resourceName)
{
throw new NotImplementedException ();
}
//
// The following functions are only for the Mono Debugger.
//
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern MethodBase MonoDebugger_GetMethod (int token);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern Type MonoDebugger_GetLocalTypeFromSignature (byte[] signature);
[MethodImplAttribute (MethodImplOptions.InternalCall)]
public extern Type MonoDebugger_GetType (int token);
}
}