Assembly.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. if (type == null)
  113. throw new ArgumentNullException ("type");
  114. string ns = type.Namespace;
  115. if (ns == null)
  116. return GetManifestResourceStream (name);
  117. else
  118. return GetManifestResourceStream (ns + "." + name);
  119. }
  120. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  121. private extern Type[] GetTypes (bool exportedOnly);
  122. public virtual Type[] GetTypes ()
  123. {
  124. return GetTypes (false);
  125. }
  126. public virtual Type[] GetExportedTypes ()
  127. {
  128. return GetTypes (true);
  129. }
  130. public virtual Type GetType (String name, Boolean throwOnError)
  131. {
  132. return GetType (name, throwOnError, false);
  133. }
  134. public virtual Type GetType (String name) {
  135. return GetType (name, false, false);
  136. }
  137. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  138. extern Type InternalGetType (String name, Boolean throwOnError, Boolean ignoreCase);
  139. public Type GetType (string name, bool throwOnError, bool ignoreCase)
  140. {
  141. if (name == null)
  142. throw new ArgumentNullException (name);
  143. return InternalGetType (name, throwOnError, ignoreCase);
  144. }
  145. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  146. static extern void FillName (Assembly ass, AssemblyName aname);
  147. public virtual AssemblyName GetName (Boolean copiedName)
  148. {
  149. AssemblyName aname = new AssemblyName ();
  150. FillName (this, aname);
  151. return aname;
  152. }
  153. public virtual AssemblyName GetName ()
  154. {
  155. return GetName (false);
  156. }
  157. public override String ToString ()
  158. {
  159. return GetName ().Name;
  160. }
  161. [MonoTODO]
  162. public static String CreateQualifiedName (String assemblyName, String typeName)
  163. {
  164. return typeName + "," + assemblyName;
  165. }
  166. public static Assembly GetAssembly (Type type)
  167. {
  168. if (type != null)
  169. return type.Assembly;
  170. throw new ArgumentNullException ("type");
  171. }
  172. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  173. public static extern Assembly GetEntryAssembly();
  174. [MonoTODO]
  175. public Assembly GetSatelliteAssembly (CultureInfo culture)
  176. {
  177. throw new NotImplementedException ();
  178. }
  179. [MonoTODO]
  180. public Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
  181. {
  182. throw new NotImplementedException ();
  183. }
  184. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  185. public extern static Assembly LoadFrom (String assemblyFile);
  186. public static Assembly Load (String assemblyString)
  187. {
  188. return AppDomain.CurrentDomain.Load (assemblyString);
  189. }
  190. public static Assembly Load (String assemblyString, Evidence assemblySecurity)
  191. {
  192. return AppDomain.CurrentDomain.Load (assemblyString, assemblySecurity);
  193. }
  194. public static Assembly Load (AssemblyName assemblyRef)
  195. {
  196. return AppDomain.CurrentDomain.Load (assemblyRef);
  197. }
  198. public static Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
  199. {
  200. return AppDomain.CurrentDomain.Load (assemblyRef, assemblySecurity);
  201. }
  202. public static Assembly Load (Byte[] rawAssembly)
  203. {
  204. return AppDomain.CurrentDomain.Load (rawAssembly);
  205. }
  206. public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore)
  207. {
  208. return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore);
  209. }
  210. public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore,
  211. Evidence securityEvidence)
  212. {
  213. return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore, securityEvidence);
  214. }
  215. public static Assembly LoadWithPartialName (string partialName)
  216. {
  217. return LoadWithPartialName (partialName, null);
  218. }
  219. [MonoTODO]
  220. public static Assembly LoadWithPartialName (string partialName, Evidence securityEvidence)
  221. {
  222. return AppDomain.CurrentDomain.Load (partialName, securityEvidence);
  223. }
  224. public Object CreateInstance (String typeName)
  225. {
  226. return CreateInstance (typeName, false);
  227. }
  228. public Object CreateInstance (String typeName, Boolean ignoreCase)
  229. {
  230. Type t = GetType (typeName, true, ignoreCase);
  231. return Activator.CreateInstance (t);
  232. }
  233. public Object CreateInstance (String typeName, Boolean ignoreCase,
  234. BindingFlags bindingAttr, Binder binder,
  235. Object[] args, CultureInfo culture,
  236. Object[] activationAttributes)
  237. {
  238. Type t = GetType (typeName, true, ignoreCase);
  239. return Activator.CreateInstance (t, bindingAttr, binder, args, culture, activationAttributes);
  240. }
  241. public Module[] GetLoadedModules ()
  242. {
  243. throw new NotImplementedException ();
  244. }
  245. public Module[] GetModules ()
  246. {
  247. throw new NotImplementedException ();
  248. }
  249. public Module GetModule (String name)
  250. {
  251. throw new NotImplementedException ();
  252. }
  253. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  254. public extern virtual String[] GetManifestResourceNames ();
  255. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  256. public extern static Assembly GetExecutingAssembly ();
  257. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  258. public extern static Assembly GetCallingAssembly ();
  259. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  260. public extern AssemblyName[] GetReferencedAssemblies ();
  261. public virtual ManifestResourceInfo GetManifestResourceInfo (String resourceName)
  262. {
  263. throw new NotImplementedException ();
  264. }
  265. //
  266. // The following functions are only for the Mono Debugger.
  267. //
  268. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  269. public extern MethodBase MonoDebugger_GetMethod (int token);
  270. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  271. public extern Type MonoDebugger_GetLocalTypeFromSignature (byte[] signature);
  272. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  273. public extern Type MonoDebugger_GetType (int token);
  274. }
  275. }