MonoAssembly.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // System.Reflection/MonoAssembly.cs
  3. //
  4. // Author:
  5. // Rodrigo Kumpera ([email protected])
  6. //
  7. // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections;
  30. using System.Globalization;
  31. using System.Runtime.InteropServices;
  32. using System.Reflection.Emit;
  33. namespace System.Reflection {
  34. #if NET_4_0 || MOONLIGHT
  35. [ComVisible (true)]
  36. [ComDefaultInterfaceAttribute (typeof (_Assembly))]
  37. [Serializable]
  38. [ClassInterface(ClassInterfaceType.None)]
  39. class MonoAssembly : Assembly {
  40. #else
  41. public partial class Assembly {
  42. #endif
  43. public
  44. #if NET_4_0 || MOONLIGHT
  45. override
  46. #endif
  47. Type GetType (string name, bool throwOnError, bool ignoreCase)
  48. {
  49. Type res;
  50. if (name == null)
  51. throw new ArgumentNullException (name);
  52. if (name.Length == 0)
  53. throw new ArgumentException ("name", "Name cannot be empty");
  54. res = InternalGetType (null, name, throwOnError, ignoreCase);
  55. #if !(NET_4_0 || MOONLIGHT)
  56. if (res is TypeBuilder) {
  57. if (throwOnError)
  58. throw new TypeLoadException (string.Format ("Could not load type '{0}' from assembly '{1}'", name, this));
  59. return null;
  60. }
  61. #endif
  62. return res;
  63. }
  64. public
  65. #if NET_4_0 || MOONLIGHT
  66. override
  67. #endif
  68. Module GetModule (String name)
  69. {
  70. if (name == null)
  71. throw new ArgumentNullException ("name");
  72. if (name.Length == 0)
  73. throw new ArgumentException ("Name can't be empty");
  74. Module[] modules = GetModules (true);
  75. foreach (Module module in modules) {
  76. if (module.ScopeName == name)
  77. return module;
  78. }
  79. return null;
  80. }
  81. public
  82. #if NET_4_0 || MOONLIGHT
  83. override
  84. #endif
  85. AssemblyName[] GetReferencedAssemblies () {
  86. return GetReferencedAssemblies (this);
  87. }
  88. public
  89. #if NET_4_0 || MOONLIGHT
  90. override
  91. #endif
  92. Module[] GetModules (bool getResourceModules) {
  93. Module[] modules = GetModulesInternal ();
  94. if (!getResourceModules) {
  95. ArrayList result = new ArrayList (modules.Length);
  96. foreach (Module m in modules)
  97. if (!m.IsResource ())
  98. result.Add (m);
  99. return (Module[])result.ToArray (typeof (Module));
  100. }
  101. else
  102. return modules;
  103. }
  104. [MonoTODO ("Always returns the same as GetModules")]
  105. public
  106. #if NET_4_0 || MOONLIGHT
  107. override
  108. #endif
  109. Module[] GetLoadedModules (bool getResourceModules)
  110. {
  111. return GetModules (getResourceModules);
  112. }
  113. public
  114. #if NET_4_0 || MOONLIGHT
  115. override
  116. #endif
  117. Assembly GetSatelliteAssembly (CultureInfo culture)
  118. {
  119. return GetSatelliteAssembly (culture, null, true);
  120. }
  121. public
  122. #if NET_4_0 || MOONLIGHT
  123. override
  124. #endif
  125. Assembly GetSatelliteAssembly (CultureInfo culture, Version version)
  126. {
  127. return GetSatelliteAssembly (culture, version, true);
  128. }
  129. //FIXME remove GetManifestModule under v4, it's a v2 artifact
  130. [ComVisible (false)]
  131. public
  132. #if NET_4_0 || MOONLIGHT
  133. override
  134. #endif
  135. Module ManifestModule {
  136. get {
  137. return GetManifestModule ();
  138. }
  139. }
  140. #if !MOONLIGHT
  141. public
  142. #if NET_4_0
  143. override
  144. #endif
  145. bool GlobalAssemblyCache {
  146. get {
  147. return get_global_assembly_cache ();
  148. }
  149. }
  150. #endif
  151. }
  152. }