| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342 |
- //
- // 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);
- }
- }
|