Assembly.cs 8.1 KB

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