Assembly.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  9. // Copyright 2011 Xamarin Inc (http://www.xamarin.com).
  10. //
  11. // Permission is hereby granted, free of charge, to any person obtaining
  12. // a copy of this software and associated documentation files (the
  13. // "Software"), to deal in the Software without restriction, including
  14. // without limitation the rights to use, copy, modify, merge, publish,
  15. // distribute, sublicense, and/or sell copies of the Software, and to
  16. // permit persons to whom the Software is furnished to do so, subject to
  17. // the following conditions:
  18. //
  19. // The above copyright notice and this permission notice shall be
  20. // included in all copies or substantial portions of the Software.
  21. //
  22. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  23. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  24. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  25. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  26. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  27. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  28. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  29. //
  30. using System.Security;
  31. using System.Security.Policy;
  32. using System.Security.Permissions;
  33. using System.Runtime.Serialization;
  34. using System.Reflection;
  35. using System.IO;
  36. using System.Globalization;
  37. using System.Runtime.CompilerServices;
  38. using System.Runtime.InteropServices;
  39. using System.Collections.Generic;
  40. using System.Configuration.Assemblies;
  41. using System.Threading;
  42. using System.Text;
  43. using System.Diagnostics.Contracts;
  44. using Mono.Security;
  45. namespace System.Reflection {
  46. [ComVisible (true)]
  47. [ComDefaultInterfaceAttribute (typeof (_Assembly))]
  48. [Serializable]
  49. [ClassInterface(ClassInterfaceType.None)]
  50. [StructLayout (LayoutKind.Sequential)]
  51. #if MOBILE
  52. public partial class Assembly : ICustomAttributeProvider, ISerializable
  53. #else
  54. public abstract class Assembly : ICustomAttributeProvider, _Assembly, IEvidenceFactory, ISerializable
  55. #endif
  56. {
  57. internal class ResolveEventHolder {
  58. #pragma warning disable 67
  59. public event ModuleResolveEventHandler ModuleResolve;
  60. #pragma warning restore
  61. }
  62. //
  63. // We can't store the event directly in this class, since the
  64. // compiler would silently insert the fields before _mono_assembly
  65. //
  66. public virtual event ModuleResolveEventHandler ModuleResolve {
  67. [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
  68. add {
  69. throw new NotImplementedException ();
  70. }
  71. [SecurityPermission (SecurityAction.LinkDemand, ControlAppDomain = true)]
  72. remove {
  73. throw new NotImplementedException ();
  74. }
  75. }
  76. public virtual string CodeBase {
  77. get {
  78. throw new NotImplementedException ();
  79. }
  80. }
  81. public virtual string EscapedCodeBase {
  82. get {
  83. throw new NotImplementedException ();
  84. }
  85. }
  86. public virtual string FullName {
  87. get {
  88. throw new NotImplementedException ();
  89. }
  90. }
  91. public virtual MethodInfo EntryPoint {
  92. get {
  93. throw new NotImplementedException ();
  94. }
  95. }
  96. public virtual Evidence Evidence {
  97. [SecurityPermission (SecurityAction.Demand, ControlEvidence = true)]
  98. get {
  99. throw new NotImplementedException ();
  100. }
  101. }
  102. internal virtual Evidence UnprotectedGetEvidence ()
  103. {
  104. throw new NotImplementedException ();
  105. }
  106. internal virtual IntPtr MonoAssembly {
  107. get {
  108. throw new NotImplementedException ();
  109. }
  110. }
  111. internal virtual bool FromByteArray {
  112. set {
  113. throw new NotImplementedException ();
  114. }
  115. }
  116. public virtual String Location {
  117. get {
  118. throw new NotImplementedException ();
  119. }
  120. }
  121. [ComVisible (false)]
  122. public virtual string ImageRuntimeVersion {
  123. get {
  124. throw new NotImplementedException ();
  125. }
  126. }
  127. public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
  128. {
  129. throw new NotImplementedException ();
  130. }
  131. public virtual bool IsDefined (Type attributeType, bool inherit)
  132. {
  133. throw new NotImplementedException ();
  134. }
  135. public virtual object [] GetCustomAttributes (bool inherit)
  136. {
  137. throw new NotImplementedException ();
  138. }
  139. public virtual object [] GetCustomAttributes (Type attributeType, bool inherit)
  140. {
  141. throw new NotImplementedException ();
  142. }
  143. public virtual FileStream[] GetFiles ()
  144. {
  145. return GetFiles (false);
  146. }
  147. public virtual FileStream [] GetFiles (bool getResourceModules)
  148. {
  149. throw new NotImplementedException ();
  150. }
  151. public virtual FileStream GetFile (String name)
  152. {
  153. throw new NotImplementedException ();
  154. }
  155. public virtual Stream GetManifestResourceStream (String name)
  156. {
  157. throw new NotImplementedException ();
  158. }
  159. public virtual Stream GetManifestResourceStream (Type type, String name)
  160. {
  161. throw new NotImplementedException ();
  162. }
  163. internal Stream GetManifestResourceStream (Type type, String name, bool skipSecurityCheck, ref StackCrawlMark stackMark)
  164. {
  165. StringBuilder sb = new StringBuilder ();
  166. if (type == null) {
  167. if (name == null)
  168. throw new ArgumentNullException ("type");
  169. } else {
  170. String nameSpace = type.Namespace;
  171. if (nameSpace != null) {
  172. sb.Append (nameSpace);
  173. if (name != null)
  174. sb.Append (Type.Delimiter);
  175. }
  176. }
  177. if (name != null)
  178. sb.Append(name);
  179. return GetManifestResourceStream (sb.ToString());
  180. }
  181. internal unsafe Stream GetManifestResourceStream(String name, ref StackCrawlMark stackMark, bool skipSecurityCheck)
  182. {
  183. return GetManifestResourceStream (null, name, skipSecurityCheck, ref stackMark);
  184. }
  185. internal String GetSimpleName()
  186. {
  187. AssemblyName aname = GetName (true);
  188. return aname.Name;
  189. }
  190. internal byte[] GetPublicKey()
  191. {
  192. AssemblyName aname = GetName (true);
  193. return aname.GetPublicKey ();
  194. }
  195. internal Version GetVersion()
  196. {
  197. AssemblyName aname = GetName (true);
  198. return aname.Version;
  199. }
  200. private AssemblyNameFlags GetFlags()
  201. {
  202. AssemblyName aname = GetName (true);
  203. return aname.Flags;
  204. }
  205. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  206. internal virtual extern Type[] GetTypes (bool exportedOnly);
  207. public virtual Type[] GetTypes ()
  208. {
  209. return GetTypes (false);
  210. }
  211. public virtual Type[] GetExportedTypes ()
  212. {
  213. throw new NotImplementedException ();
  214. }
  215. public virtual Type GetType (String name, Boolean throwOnError)
  216. {
  217. return GetType (name, throwOnError, false);
  218. }
  219. public virtual Type GetType (String name) {
  220. return GetType (name, false, false);
  221. }
  222. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  223. internal extern Type InternalGetType (Module module, String name, Boolean throwOnError, Boolean ignoreCase);
  224. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  225. internal extern unsafe static void InternalGetAssemblyName (string assemblyFile, out Mono.MonoAssemblyName aname, out string codebase);
  226. public virtual AssemblyName GetName (Boolean copiedName)
  227. {
  228. throw new NotImplementedException ();
  229. }
  230. public virtual AssemblyName GetName ()
  231. {
  232. return GetName (false);
  233. }
  234. public override string ToString ()
  235. {
  236. return base.ToString ();
  237. }
  238. public static String CreateQualifiedName (String assemblyName, String typeName)
  239. {
  240. return typeName + ", " + assemblyName;
  241. }
  242. public static Assembly GetAssembly (Type type)
  243. {
  244. if (type != null)
  245. return type.Assembly;
  246. throw new ArgumentNullException ("type");
  247. }
  248. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  249. public static extern Assembly GetEntryAssembly();
  250. internal Assembly GetSatelliteAssembly (CultureInfo culture, Version version, bool throwOnError, ref StackCrawlMark stackMark)
  251. {
  252. if (culture == null)
  253. throw new ArgumentNullException("culture");
  254. Contract.EndContractBlock();
  255. String name = GetSimpleName() + ".resources";
  256. return InternalGetSatelliteAssembly(name, culture, version, true, ref stackMark);
  257. }
  258. internal RuntimeAssembly InternalGetSatelliteAssembly (String name, CultureInfo culture, Version version, bool throwOnFileNotFound, ref StackCrawlMark stackMark)
  259. {
  260. AssemblyName an = new AssemblyName ();
  261. an.SetPublicKey (GetPublicKey ());
  262. an.Flags = GetFlags () | AssemblyNameFlags.PublicKey;
  263. if (version == null)
  264. an.Version = GetVersion ();
  265. else
  266. an.Version = version;
  267. an.CultureInfo = culture;
  268. an.Name = name;
  269. Assembly assembly;
  270. try {
  271. assembly = AppDomain.CurrentDomain.LoadSatellite (an, false, ref stackMark);
  272. if (assembly != null)
  273. return (RuntimeAssembly)assembly;
  274. } catch (FileNotFoundException) {
  275. assembly = null;
  276. // ignore
  277. }
  278. if (String.IsNullOrEmpty (Location))
  279. return null;
  280. // Try the assembly directory
  281. string location = Path.GetDirectoryName (Location);
  282. string fullName = Path.Combine (location, Path.Combine (culture.Name, an.Name + ".dll"));
  283. try {
  284. return (RuntimeAssembly)LoadFrom (fullName, false, ref stackMark);
  285. } catch {
  286. if (!throwOnFileNotFound && !File.Exists (fullName))
  287. return null;
  288. throw;
  289. }
  290. }
  291. #if !MOBILE
  292. Type _Assembly.GetType ()
  293. {
  294. // Required or object::GetType becomes virtual final
  295. return base.GetType ();
  296. }
  297. #endif
  298. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  299. private extern static Assembly LoadFrom (String assemblyFile, bool refOnly, ref StackCrawlMark stackMark);
  300. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  301. private extern static Assembly LoadFile_internal (String assemblyFile, ref StackCrawlMark stackMark);
  302. [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
  303. public static Assembly LoadFrom (String assemblyFile)
  304. {
  305. StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
  306. return LoadFrom (assemblyFile, false, ref stackMark);
  307. }
  308. [Obsolete]
  309. [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
  310. public static Assembly LoadFrom (String assemblyFile, Evidence securityEvidence)
  311. {
  312. StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
  313. Assembly a = LoadFrom (assemblyFile, false, ref stackMark);
  314. #if !MOBILE
  315. if ((a != null) && (securityEvidence != null)) {
  316. // merge evidence (i.e. replace defaults with provided evidences)
  317. a.Evidence.Merge (securityEvidence);
  318. }
  319. #endif
  320. return a;
  321. }
  322. [Obsolete]
  323. [MonoTODO("This overload is not currently implemented")]
  324. // FIXME: What are we missing?
  325. public static Assembly LoadFrom (String assemblyFile, Evidence securityEvidence, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
  326. {
  327. throw new NotImplementedException ();
  328. }
  329. [MonoTODO]
  330. public static Assembly LoadFrom (String assemblyFile, byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm)
  331. {
  332. throw new NotImplementedException ();
  333. }
  334. [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
  335. public static Assembly UnsafeLoadFrom (String assemblyFile)
  336. {
  337. StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
  338. return LoadFrom (assemblyFile, false, ref stackMark);
  339. }
  340. [Obsolete]
  341. [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
  342. public static Assembly LoadFile (String path, Evidence securityEvidence)
  343. {
  344. if (path == null)
  345. throw new ArgumentNullException ("path");
  346. if (path == String.Empty)
  347. throw new ArgumentException ("Path can't be empty", "path");
  348. StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
  349. Assembly a = LoadFile_internal (path, ref stackMark);
  350. if (a != null && securityEvidence != null) {
  351. throw new NotImplementedException ();
  352. }
  353. return a;
  354. }
  355. public static Assembly LoadFile (String path)
  356. {
  357. return LoadFile (path, null);
  358. }
  359. public static Assembly Load (String assemblyString)
  360. {
  361. return AppDomain.CurrentDomain.Load (assemblyString);
  362. }
  363. [Obsolete]
  364. public static Assembly Load (String assemblyString, Evidence assemblySecurity)
  365. {
  366. return AppDomain.CurrentDomain.Load (assemblyString, assemblySecurity);
  367. }
  368. public static Assembly Load (AssemblyName assemblyRef)
  369. {
  370. return AppDomain.CurrentDomain.Load (assemblyRef);
  371. }
  372. [Obsolete]
  373. public static Assembly Load (AssemblyName assemblyRef, Evidence assemblySecurity)
  374. {
  375. return AppDomain.CurrentDomain.Load (assemblyRef, assemblySecurity);
  376. }
  377. public static Assembly Load (Byte[] rawAssembly)
  378. {
  379. return AppDomain.CurrentDomain.Load (rawAssembly);
  380. }
  381. public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore)
  382. {
  383. return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore);
  384. }
  385. [Obsolete]
  386. public static Assembly Load (Byte[] rawAssembly, Byte[] rawSymbolStore,
  387. Evidence securityEvidence)
  388. {
  389. return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore, securityEvidence);
  390. }
  391. [MonoLimitation ("Argument securityContextSource is ignored")]
  392. public static Assembly Load (byte [] rawAssembly, byte [] rawSymbolStore, SecurityContextSource securityContextSource)
  393. {
  394. return AppDomain.CurrentDomain.Load (rawAssembly, rawSymbolStore);
  395. }
  396. public static Assembly ReflectionOnlyLoad (byte[] rawAssembly)
  397. {
  398. return AppDomain.CurrentDomain.Load (rawAssembly, null, null, true);
  399. }
  400. [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
  401. public static Assembly ReflectionOnlyLoad (string assemblyString)
  402. {
  403. StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
  404. return AppDomain.CurrentDomain.Load (assemblyString, null, true, ref stackMark);
  405. }
  406. [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
  407. public static Assembly ReflectionOnlyLoadFrom (string assemblyFile)
  408. {
  409. if (assemblyFile == null)
  410. throw new ArgumentNullException ("assemblyFile");
  411. StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
  412. return LoadFrom (assemblyFile, true, ref stackMark);
  413. }
  414. [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")]
  415. public static Assembly LoadWithPartialName (string partialName)
  416. {
  417. return LoadWithPartialName (partialName, null);
  418. }
  419. [MonoTODO ("Not implemented")]
  420. public Module LoadModule (string moduleName, byte [] rawModule)
  421. {
  422. throw new NotImplementedException ();
  423. }
  424. [MonoTODO ("Not implemented")]
  425. public
  426. virtual
  427. Module LoadModule (string moduleName, byte [] rawModule, byte [] rawSymbolStore)
  428. {
  429. throw new NotImplementedException ();
  430. }
  431. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  432. private static extern Assembly load_with_partial_name (string name, Evidence e);
  433. [Obsolete("This method has been deprecated. Please use Assembly.Load() instead. http://go.microsoft.com/fwlink/?linkid=14202")]
  434. public static Assembly LoadWithPartialName (string partialName, Evidence securityEvidence)
  435. {
  436. return LoadWithPartialName (partialName, securityEvidence, true);
  437. }
  438. /**
  439. * LAMESPEC: It is possible for this method to throw exceptions IF the name supplied
  440. * is a valid gac name and contains filesystem entry charachters at the end of the name
  441. * ie System/// will throw an exception. However ////System will not as that is canocolized
  442. * out of the name.
  443. */
  444. // FIXME: LoadWithPartialName must look cache (no CAS) or read from disk (CAS)
  445. internal static Assembly LoadWithPartialName (string partialName, Evidence securityEvidence, bool oldBehavior)
  446. {
  447. if (!oldBehavior)
  448. throw new NotImplementedException ();
  449. if (partialName == null)
  450. throw new NullReferenceException ();
  451. return load_with_partial_name (partialName, securityEvidence);
  452. }
  453. public Object CreateInstance (String typeName)
  454. {
  455. return CreateInstance (typeName, false);
  456. }
  457. public Object CreateInstance (String typeName, Boolean ignoreCase)
  458. {
  459. Type t = GetType (typeName, false, ignoreCase);
  460. if (t == null)
  461. return null;
  462. try {
  463. return Activator.CreateInstance (t);
  464. } catch (InvalidOperationException) {
  465. throw new ArgumentException ("It is illegal to invoke a method on a Type loaded via ReflectionOnly methods.");
  466. }
  467. }
  468. public
  469. virtual
  470. Object CreateInstance (String typeName, Boolean ignoreCase,
  471. BindingFlags bindingAttr, Binder binder,
  472. Object[] args, CultureInfo culture,
  473. Object[] activationAttributes)
  474. {
  475. Type t = GetType (typeName, false, ignoreCase);
  476. if (t == null)
  477. return null;
  478. try {
  479. return Activator.CreateInstance (t, bindingAttr, binder, args, culture, activationAttributes);
  480. } catch (InvalidOperationException) {
  481. throw new ArgumentException ("It is illegal to invoke a method on a Type loaded via ReflectionOnly methods.");
  482. }
  483. }
  484. public Module[] GetLoadedModules ()
  485. {
  486. return GetLoadedModules (false);
  487. }
  488. public Module[] GetModules ()
  489. {
  490. return GetModules (false);
  491. }
  492. internal virtual Module[] GetModulesInternal () {
  493. throw new NotImplementedException ();
  494. }
  495. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  496. public extern static Assembly GetExecutingAssembly ();
  497. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  498. public extern static Assembly GetCallingAssembly ();
  499. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  500. internal static extern IntPtr InternalGetReferencedAssemblies (Assembly module);
  501. public virtual String[] GetManifestResourceNames ()
  502. {
  503. throw new NotImplementedException ();
  504. }
  505. internal static AssemblyName[] GetReferencedAssemblies (Assembly module)
  506. {
  507. using (var nativeNames = new Mono.SafeGPtrArrayHandle (InternalGetReferencedAssemblies (module))) {
  508. var numAssemblies = nativeNames.Length;
  509. try {
  510. AssemblyName [] result = new AssemblyName[numAssemblies];
  511. const bool addVersion = true;
  512. const bool addPublicKey = false;
  513. const bool defaultToken = true;
  514. const bool assemblyRef = true;
  515. for (int i = 0; i < numAssemblies; i++) {
  516. AssemblyName name = new AssemblyName ();
  517. unsafe {
  518. Mono.MonoAssemblyName *nativeName = (Mono.MonoAssemblyName*) nativeNames[i];
  519. name.FillName (nativeName, null, addVersion, addPublicKey, defaultToken, assemblyRef);
  520. result[i] = name;
  521. }
  522. }
  523. return result;
  524. } finally {
  525. for (int i = 0; i < numAssemblies; i++) {
  526. unsafe {
  527. Mono.MonoAssemblyName* nativeName = (Mono.MonoAssemblyName*) nativeNames[i];
  528. Mono.RuntimeMarshal.FreeAssemblyName (ref *nativeName, true);
  529. }
  530. }
  531. }
  532. }
  533. }
  534. public virtual ManifestResourceInfo GetManifestResourceInfo (String resourceName)
  535. {
  536. throw new NotImplementedException ();
  537. }
  538. [MonoTODO ("Currently it always returns zero")]
  539. [ComVisible (false)]
  540. public
  541. virtual
  542. long HostContext {
  543. get { return 0; }
  544. }
  545. internal virtual Module GetManifestModule () {
  546. throw new NotImplementedException ();
  547. }
  548. [ComVisible (false)]
  549. public virtual bool ReflectionOnly {
  550. get {
  551. throw new NotImplementedException ();
  552. }
  553. }
  554. public override int GetHashCode ()
  555. {
  556. return base.GetHashCode ();
  557. }
  558. public override bool Equals (object o)
  559. {
  560. return base.Equals (o);
  561. }
  562. #if !MOBILE
  563. internal virtual PermissionSet GrantedPermissionSet {
  564. get {
  565. throw new NotImplementedException ();
  566. }
  567. }
  568. internal virtual PermissionSet DeniedPermissionSet {
  569. get {
  570. throw new NotImplementedException ();
  571. }
  572. }
  573. public virtual PermissionSet PermissionSet {
  574. get {
  575. throw new NotImplementedException ();
  576. }
  577. }
  578. #endif
  579. public virtual SecurityRuleSet SecurityRuleSet {
  580. get { throw CreateNIE (); }
  581. }
  582. static Exception CreateNIE ()
  583. {
  584. return new NotImplementedException ("Derived classes must implement it");
  585. }
  586. public virtual IList<CustomAttributeData> GetCustomAttributesData ()
  587. {
  588. throw new NotImplementedException ();
  589. }
  590. [MonoTODO]
  591. public bool IsFullyTrusted {
  592. get { return true; }
  593. }
  594. public virtual Type GetType (string name, bool throwOnError, bool ignoreCase)
  595. {
  596. throw CreateNIE ();
  597. }
  598. public virtual Module GetModule (String name)
  599. {
  600. throw CreateNIE ();
  601. }
  602. public virtual AssemblyName[] GetReferencedAssemblies ()
  603. {
  604. throw CreateNIE ();
  605. }
  606. public virtual Module[] GetModules (bool getResourceModules)
  607. {
  608. throw CreateNIE ();
  609. }
  610. [MonoTODO ("Always returns the same as GetModules")]
  611. public virtual Module[] GetLoadedModules (bool getResourceModules)
  612. {
  613. throw CreateNIE ();
  614. }
  615. public virtual Assembly GetSatelliteAssembly (CultureInfo culture)
  616. {
  617. throw CreateNIE ();
  618. }
  619. public virtual Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
  620. {
  621. throw CreateNIE ();
  622. }
  623. public virtual Module ManifestModule {
  624. get { throw CreateNIE (); }
  625. }
  626. public virtual bool GlobalAssemblyCache {
  627. get { throw CreateNIE (); }
  628. }
  629. public virtual bool IsDynamic {
  630. get { return false; }
  631. }
  632. public static bool operator == (Assembly left, Assembly right)
  633. {
  634. if ((object)left == (object)right)
  635. return true;
  636. if ((object)left == null ^ (object)right == null)
  637. return false;
  638. return left.Equals (right);
  639. }
  640. public static bool operator != (Assembly left, Assembly right)
  641. {
  642. if ((object)left == (object)right)
  643. return false;
  644. if ((object)left == null ^ (object)right == null)
  645. return true;
  646. return !left.Equals (right);
  647. }
  648. public virtual IEnumerable<TypeInfo> DefinedTypes {
  649. get {
  650. foreach (var type in GetTypes ()) {
  651. yield return type.GetTypeInfo ();
  652. }
  653. }
  654. }
  655. public virtual IEnumerable<Type> ExportedTypes {
  656. get { return GetExportedTypes (); }
  657. }
  658. public virtual IEnumerable<Module> Modules {
  659. get { return GetModules (); }
  660. }
  661. public virtual IEnumerable<CustomAttributeData> CustomAttributes {
  662. get { return GetCustomAttributesData (); }
  663. }
  664. public virtual Type[] GetForwardedTypes() => throw new PlatformNotSupportedException();
  665. }
  666. }