MethodBase.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. //
  2. // System.Reflection/MethodBase.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. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System.Diagnostics;
  30. using System.Globalization;
  31. using System.Reflection.Emit;
  32. using System.Runtime.CompilerServices;
  33. using System.Runtime.InteropServices;
  34. namespace System.Reflection {
  35. #if NET_2_0
  36. [ComVisible (true)]
  37. [ComDefaultInterfaceAttribute (typeof (_MethodBase))]
  38. #endif
  39. [Serializable]
  40. [ClassInterface(ClassInterfaceType.None)]
  41. public abstract class MethodBase: MemberInfo, _MethodBase {
  42. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  43. public extern static MethodBase GetCurrentMethod ();
  44. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  45. private extern static MethodBase GetMethodFromHandleInternal(IntPtr handle);
  46. public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) {
  47. return GetMethodFromHandleInternal (handle.Value);
  48. }
  49. public abstract MethodImplAttributes GetMethodImplementationFlags();
  50. public abstract ParameterInfo[] GetParameters();
  51. //
  52. // This is a quick version for our own use. We should override
  53. // it where possible so that it does not allocate an array.
  54. //
  55. internal virtual int GetParameterCount ()
  56. {
  57. ParameterInfo [] pi = GetParameters ();
  58. if (pi == null)
  59. return 0;
  60. return pi.Length;
  61. }
  62. #if ONLY_1_1
  63. public new Type GetType ()
  64. {
  65. return base.GetType ();
  66. }
  67. #endif
  68. [DebuggerHidden]
  69. [DebuggerStepThrough]
  70. #if NET_2_0 || BOOTSTRAP_NET_2_0
  71. virtual
  72. #endif
  73. public Object Invoke(Object obj, Object[] parameters) {
  74. return Invoke (obj, 0, null, parameters, null);
  75. }
  76. public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
  77. protected MethodBase()
  78. {
  79. }
  80. public abstract RuntimeMethodHandle MethodHandle { get; }
  81. public abstract MethodAttributes Attributes { get; }
  82. public virtual CallingConventions CallingConvention { get {return CallingConventions.Standard;} }
  83. public Boolean IsPublic {
  84. get {
  85. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
  86. }
  87. }
  88. public Boolean IsPrivate {
  89. get {
  90. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
  91. }
  92. }
  93. public Boolean IsFamily {
  94. get {
  95. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
  96. }
  97. }
  98. public Boolean IsAssembly {
  99. get {
  100. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
  101. }
  102. }
  103. public Boolean IsFamilyAndAssembly {
  104. get {
  105. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
  106. }
  107. }
  108. public Boolean IsFamilyOrAssembly {
  109. get {
  110. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
  111. }
  112. }
  113. public Boolean IsStatic {
  114. get {
  115. return (Attributes & MethodAttributes.Static) != 0;
  116. }
  117. }
  118. public Boolean IsFinal {
  119. get {
  120. return (Attributes & MethodAttributes.Final) != 0;
  121. }
  122. }
  123. public Boolean IsVirtual {
  124. get {
  125. return (Attributes & MethodAttributes.Virtual) != 0;
  126. }
  127. }
  128. public Boolean IsHideBySig {
  129. get {
  130. return (Attributes & MethodAttributes.HideBySig) != 0;
  131. }
  132. }
  133. public Boolean IsAbstract {
  134. get {
  135. return (Attributes & MethodAttributes.Abstract) != 0;
  136. }
  137. }
  138. public Boolean IsSpecialName {
  139. get {
  140. int attr = (int)Attributes;
  141. return (attr & (int)MethodAttributes.SpecialName) != 0;
  142. }
  143. }
  144. public Boolean IsConstructor {
  145. get {
  146. int attr = (int)Attributes;
  147. return ((attr & (int)MethodAttributes.RTSpecialName) != 0
  148. && (Name == ".ctor"));
  149. }
  150. }
  151. internal virtual int get_next_table_index (object obj, int table, bool inc) {
  152. if (this is MethodBuilder) {
  153. MethodBuilder mb = (MethodBuilder)this;
  154. return mb.get_next_table_index (obj, table, inc);
  155. }
  156. if (this is ConstructorBuilder) {
  157. ConstructorBuilder mb = (ConstructorBuilder)this;
  158. return mb.get_next_table_index (obj, table, inc);
  159. }
  160. throw new Exception ("Method is not a builder method");
  161. }
  162. #if NET_2_0 || BOOTSTRAP_NET_2_0
  163. public virtual MethodInfo MakeGenericMethod (Type [] types)
  164. {
  165. throw new NotSupportedException (this.GetType().ToString ());
  166. }
  167. public virtual Type [] GetGenericArguments ()
  168. {
  169. throw new NotSupportedException ();
  170. }
  171. public virtual MethodInfo GetGenericMethodDefinition ()
  172. {
  173. throw new NotSupportedException ();
  174. }
  175. public virtual bool Mono_IsInflatedMethod {
  176. get {
  177. throw new NotSupportedException ();
  178. }
  179. }
  180. public virtual bool HasGenericParameters {
  181. get {
  182. throw new NotSupportedException ();
  183. }
  184. }
  185. public virtual bool IsGenericMethodDefinition {
  186. get {
  187. throw new NotSupportedException ();
  188. }
  189. }
  190. #endif
  191. #if NET_2_0
  192. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  193. internal extern static MethodBody GetMethodBodyInternal (IntPtr handle);
  194. internal static MethodBody GetMethodBody (IntPtr handle) {
  195. MethodBody mb = GetMethodBodyInternal (handle);
  196. if (mb == null)
  197. throw new ArgumentException ("Only methods with IL bodies are supported.");
  198. else
  199. return mb;
  200. }
  201. public virtual MethodBody GetMethodBody () {
  202. throw new NotSupportedException ();
  203. }
  204. #endif
  205. void _MethodBase.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
  206. {
  207. throw new NotImplementedException ();
  208. }
  209. void _MethodBase.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
  210. {
  211. throw new NotImplementedException ();
  212. }
  213. void _MethodBase.GetTypeInfoCount (out uint pcTInfo)
  214. {
  215. throw new NotImplementedException ();
  216. }
  217. void _MethodBase.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
  218. {
  219. throw new NotImplementedException ();
  220. }
  221. }
  222. }