Module.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. //
  2. // System.Reflection/Module.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.Reflection;
  11. using System.Runtime.Serialization;
  12. using System.Security.Cryptography.X509Certificates;
  13. using System.Runtime.InteropServices;
  14. using System.Runtime.CompilerServices;
  15. namespace System.Reflection {
  16. [Serializable]
  17. public class Module : ISerializable, ICustomAttributeProvider {
  18. public static readonly TypeFilter FilterTypeName;
  19. public static readonly TypeFilter FilterTypeNameIgnoreCase;
  20. private IntPtr _impl; /* a pointer to a MonoImage */
  21. internal Assembly assembly;
  22. internal string fqname;
  23. internal string name;
  24. internal string scopename;
  25. internal bool is_resource;
  26. internal Module () { }
  27. ~Module () {
  28. Close ();
  29. }
  30. public Assembly Assembly {
  31. get { return assembly; }
  32. }
  33. public virtual string FullyQualifiedName {
  34. get { return fqname; }
  35. }
  36. public string Name {
  37. get { return name; }
  38. }
  39. public string ScopeName {
  40. get { return scopename; }
  41. }
  42. [MonoTODO]
  43. public virtual Type[] FindTypes(TypeFilter filter, object filterCriteria)
  44. {
  45. return null;
  46. }
  47. public virtual object[] GetCustomAttributes(bool inherit)
  48. {
  49. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  50. }
  51. public virtual object[] GetCustomAttributes(Type attributeType, bool inherit)
  52. {
  53. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  54. }
  55. public FieldInfo GetField (string name)
  56. {
  57. if (IsResource ())
  58. return null;
  59. return GetGlobalType ().GetField (name, BindingFlags.Public | BindingFlags.Static);
  60. }
  61. public FieldInfo GetField (string name, BindingFlags flags)
  62. {
  63. if (IsResource ())
  64. return null;
  65. return GetGlobalType ().GetField (name, flags);
  66. }
  67. public FieldInfo[] GetFields ()
  68. {
  69. if (IsResource ())
  70. return new FieldInfo [0];
  71. return GetGlobalType ().GetFields (BindingFlags.Public | BindingFlags.Static);
  72. }
  73. [MonoTODO]
  74. public MethodInfo GetMethod (string name)
  75. {
  76. if (IsResource ())
  77. return null;
  78. return null;
  79. }
  80. [MonoTODO]
  81. public MethodInfo GetMethod (string name, Type[] types)
  82. {
  83. if (IsResource ())
  84. return null;
  85. return null;
  86. }
  87. [MonoTODO]
  88. public MethodInfo GetMethod (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
  89. {
  90. if (IsResource ())
  91. return null;
  92. return null;
  93. }
  94. [MonoTODO]
  95. protected virtual MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
  96. {
  97. if (IsResource ())
  98. return null;
  99. return null;
  100. }
  101. [MonoTODO]
  102. public MethodInfo[] GetMethods ()
  103. {
  104. if (IsResource ())
  105. return new MethodInfo [0];
  106. return null;
  107. }
  108. [MonoTODO]
  109. public virtual void GetObjectData (SerializationInfo info, StreamingContext context)
  110. {
  111. }
  112. public X509Certificate GetSignerCertificate ()
  113. {
  114. try {
  115. return X509Certificate.CreateFromSignedFile (assembly.Location);
  116. }
  117. catch {
  118. return null;
  119. }
  120. }
  121. public virtual Type GetType(string className)
  122. {
  123. return GetType (className, false, false);
  124. }
  125. public virtual Type GetType(string className, bool ignoreCase)
  126. {
  127. return GetType (className, false, ignoreCase);
  128. }
  129. public virtual Type GetType(string className, bool throwOnError, bool ignoreCase)
  130. {
  131. if (className == null)
  132. throw new ArgumentNullException ("className");
  133. if (className == String.Empty)
  134. throw new ArgumentException ("Type name can't be empty");
  135. return assembly.InternalGetType (this, className, throwOnError, ignoreCase);
  136. }
  137. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  138. private extern Type[] InternalGetTypes ();
  139. public virtual Type[] GetTypes()
  140. {
  141. return InternalGetTypes ();
  142. }
  143. public virtual bool IsDefined (Type attributeType, bool inherit)
  144. {
  145. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  146. }
  147. public bool IsResource()
  148. {
  149. return is_resource;
  150. }
  151. public override string ToString ()
  152. {
  153. return "Reflection.Module: " + name;
  154. }
  155. // Mono Extension: returns the GUID of this module
  156. public Guid Mono_GetGuid ()
  157. {
  158. return new Guid (GetGuidInternal ());
  159. }
  160. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  161. private extern string GetGuidInternal ();
  162. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  163. private extern Type GetGlobalType ();
  164. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  165. private extern void Close ();
  166. }
  167. }