Assembly.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. //
  2. // System.Reflection/Assembly.cs
  3. //
  4. // Author:
  5. // Paolo Molaro ([email protected])
  6. //
  7. // (C) 2001 Ximian, Inc. http://www.ximian.com
  8. //
  9. using System;
  10. using System.Security.Policy;
  11. using System.Runtime.Serialization;
  12. using System.Reflection.Emit;
  13. using System.IO;
  14. using System.Globalization;
  15. using System.Runtime.CompilerServices;
  16. namespace System.Reflection {
  17. [Serializable]
  18. public class Assembly : System.Reflection.ICustomAttributeProvider,
  19. System.Security.IEvidenceFactory, System.Runtime.Serialization.ISerializable {
  20. private IntPtr _mono_assembly;
  21. internal Assembly () {}
  22. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  23. private extern string get_code_base ();
  24. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  25. private extern string get_location ();
  26. public virtual string CodeBase {
  27. get {
  28. return get_code_base ();
  29. }
  30. }
  31. internal virtual string CopiedCodeBase {
  32. get {
  33. return get_code_base ();
  34. }
  35. }
  36. public virtual string FullName {
  37. get {
  38. //
  39. // FIXME: This is wrong, but it gets us going
  40. // in the compiler for now
  41. //
  42. return GetName (false).ToString ();
  43. }
  44. }
  45. public virtual extern MethodInfo EntryPoint {
  46. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  47. get;
  48. }
  49. public virtual Evidence Evidence {
  50. get {
  51. return null;
  52. }
  53. }
  54. public virtual String Location {
  55. get {
  56. return get_location ();
  57. }
  58. }
  59. public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
  60. {
  61. }
  62. public virtual bool IsDefined (Type attributeType, bool inherit)
  63. {
  64. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  65. }
  66. public virtual object [] GetCustomAttributes (bool inherit)
  67. {
  68. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  69. }
  70. public virtual object [] GetCustomAttributes (Type attributeType, bool inherit)
  71. {
  72. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  73. }
  74. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  75. private extern object GetFilesInternal (String name);
  76. public virtual FileStream[] GetFiles ()
  77. {
  78. string[] names = (string[])GetFilesInternal (null);
  79. FileStream[] res = new FileStream [names.Length];
  80. for (int i = 0; i < names.Length; ++i)
  81. res [i] = new FileStream (names [i], FileMode.Open, FileAccess.Read);
  82. return res;
  83. }
  84. public virtual FileStream GetFile (String name)
  85. {
  86. if (name == null)
  87. throw new ArgumentNullException ("name");
  88. string filename = (string)GetFilesInternal (name);
  89. if (filename != null)
  90. return new FileStream (filename, FileMode.Open, FileAccess.Read);
  91. else
  92. return null;
  93. }
  94. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  95. private extern object GetManifestResourceInternal (String name);
  96. public virtual Stream GetManifestResourceStream (String name)
  97. {
  98. if (name == null)
  99. throw new ArgumentNullException ("name");
  100. object data = GetManifestResourceInternal (name);
  101. string filename = data as string;
  102. if (data == null)
  103. return null;
  104. if (filename != null) {
  105. return new FileStream (filename, FileMode.Open, FileAccess.Read);
  106. } else {
  107. return new MemoryStream ((byte[])data, false);
  108. }
  109. }
  110. public virtual Stream GetManifestResourceStream (Type type, String name)
  111. {
  112. throw new NotImplementedException ();
  113. }
  114. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  115. private extern Type[] GetTypes (bool exportedOnly);
  116. public virtual Type[] GetTypes ()
  117. {
  118. return GetTypes (false);
  119. }
  120. public virtual Type[] GetExportedTypes ()
  121. {
  122. return GetTypes (true);
  123. }
  124. public virtual Type GetType (String name, Boolean throwOnError)
  125. {
  126. return GetType (name, throwOnError, false);
  127. }
  128. public virtual Type GetType (String name) {
  129. return GetType (name, false, false);
  130. }
  131. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  132. extern Type InternalGetType (String name, Boolean throwOnError, Boolean ignoreCase);
  133. public Type GetType (string name, bool throwOnError, bool ignoreCase)
  134. {
  135. if (name == null)
  136. throw new ArgumentNullException (name);
  137. return InternalGetType (name, throwOnError, ignoreCase);
  138. }
  139. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  140. static extern void FillName (Assembly ass, AssemblyName aname);
  141. public virtual AssemblyName GetName (Boolean copiedName)
  142. {
  143. AssemblyName aname = new AssemblyName ();
  144. FillName (this, aname);
  145. return aname;
  146. }
  147. public virtual AssemblyName GetName ()
  148. {
  149. return GetName (false);
  150. }
  151. public override String ToString ()
  152. {
  153. return GetName ().Name;
  154. }
  155. [MonoTODO]
  156. public static String CreateQualifiedName (String assemblyName, String typeName)
  157. {
  158. return typeName + "," + assemblyName;
  159. }
  160. public static Assembly GetAssembly (Type type)
  161. {
  162. if (type != null)
  163. return type.Assembly;
  164. throw new ArgumentNullException ("type");
  165. }
  166. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  167. public static extern Assembly GetEntryAssembly();
  168. [MonoTODO]
  169. public Assembly GetSatelliteAssembly (CultureInfo culture)
  170. {
  171. throw new NotImplementedException ();
  172. }
  173. [MonoTODO]
  174. public Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
  175. {
  176. throw new NotImplementedException ();
  177. }
  178. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  179. public extern static Assembly LoadFrom (String assemblyFile);
  180. public static Assembly Load (String assemblyString)
  181. {
  182. return AppDomain.CurrentDomain.Load (assemblyString);
  183. }
  184. public static Assembly Load (String assemblyString, Evidence assemblySecurity)
  185. {
  186. return AppDomain.CurrentDomain.Load (assemblyString, assemblySecurity);
  187. }
  188. public static Assembly Load (AssemblyName assemblyRef)
  189. {
  190. return AppDomain.CurrentDomain.Load (assemblyRef);
  191. }
  192. public static Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
  193. {
  194. return AppDomain.CurrentDomain.Load (assemblyRef, assemblySecurity);
  195. }
  196. public static Assembly Load (Byte[] rawAssembly)
  197. {
  198. return AppDomain.CurrentDomain.Load (rawAssembly);
  199. }
  200. public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore)
  201. {
  202. return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore);
  203. }
  204. public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore,
  205. Evidence securityEvidence)
  206. {
  207. return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore, securityEvidence);
  208. }
  209. public static Assembly LoadWithPartialName (string partialName)
  210. {
  211. return LoadWithPartialName (partialName, null);
  212. }
  213. [MonoTODO]
  214. public static Assembly LoadWithPartialName (string partialName, Evidence securityEvidence)
  215. {
  216. return AppDomain.CurrentDomain.Load (partialName, securityEvidence);
  217. }
  218. public Object CreateInstance (String typeName)
  219. {
  220. return CreateInstance (typeName, false);
  221. }
  222. public Object CreateInstance (String typeName, Boolean ignoreCase)
  223. {
  224. Type t = GetType (typeName, true, ignoreCase);
  225. return Activator.CreateInstance (t);
  226. }
  227. public Object CreateInstance (String typeName, Boolean ignoreCase,
  228. BindingFlags bindingAttr, Binder binder,
  229. Object[] args, CultureInfo culture,
  230. Object[] activationAttributes)
  231. {
  232. Type t = GetType (typeName, true, ignoreCase);
  233. return Activator.CreateInstance (t, bindingAttr, binder, args, culture, activationAttributes);
  234. }
  235. public Module[] GetLoadedModules ()
  236. {
  237. throw new NotImplementedException ();
  238. }
  239. public Module[] GetModules ()
  240. {
  241. throw new NotImplementedException ();
  242. }
  243. public Module GetModule (String name)
  244. {
  245. throw new NotImplementedException ();
  246. }
  247. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  248. public extern virtual String[] GetManifestResourceNames ();
  249. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  250. public extern static Assembly GetExecutingAssembly ();
  251. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  252. public extern static Assembly GetCallingAssembly ();
  253. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  254. public extern AssemblyName[] GetReferencedAssemblies ();
  255. public virtual ManifestResourceInfo GetManifestResourceInfo (String resourceName)
  256. {
  257. throw new NotImplementedException ();
  258. }
  259. //
  260. // The following functions are only for the Mono Debugger.
  261. //
  262. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  263. public extern MethodBase MonoDebugger_GetMethod (int token);
  264. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  265. public extern Type MonoDebugger_GetLocalTypeFromSignature (byte[] signature);
  266. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  267. public extern Type MonoDebugger_GetType (int token);
  268. }
  269. }