MethodBase.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle) {
  45. return GetMethodFromHandleInternalType (handle.Value, IntPtr.Zero);
  46. }
  47. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  48. private extern static MethodBase GetMethodFromHandleInternalType (IntPtr method_handle, IntPtr type_handle);
  49. #if NET_2_0
  50. [ComVisible (false)]
  51. public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle, RuntimeTypeHandle declaringType) {
  52. return GetMethodFromHandleInternalType (handle.Value, declaringType.Value);
  53. }
  54. #endif
  55. public abstract MethodImplAttributes GetMethodImplementationFlags();
  56. public abstract ParameterInfo[] GetParameters();
  57. //
  58. // This is a quick version for our own use. We should override
  59. // it where possible so that it does not allocate an array.
  60. //
  61. internal virtual int GetParameterCount ()
  62. {
  63. ParameterInfo [] pi = GetParameters ();
  64. if (pi == null)
  65. return 0;
  66. return pi.Length;
  67. }
  68. #if ONLY_1_1
  69. public new Type GetType ()
  70. {
  71. return base.GetType ();
  72. }
  73. #endif
  74. [DebuggerHidden]
  75. [DebuggerStepThrough]
  76. public Object Invoke(Object obj, Object[] parameters) {
  77. return Invoke (obj, 0, null, parameters, null);
  78. }
  79. public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
  80. protected MethodBase()
  81. {
  82. }
  83. public abstract RuntimeMethodHandle MethodHandle { get; }
  84. public abstract MethodAttributes Attributes { get; }
  85. public virtual CallingConventions CallingConvention { get {return CallingConventions.Standard;} }
  86. public Boolean IsPublic {
  87. get {
  88. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
  89. }
  90. }
  91. public Boolean IsPrivate {
  92. get {
  93. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
  94. }
  95. }
  96. public Boolean IsFamily {
  97. get {
  98. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
  99. }
  100. }
  101. public Boolean IsAssembly {
  102. get {
  103. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
  104. }
  105. }
  106. public Boolean IsFamilyAndAssembly {
  107. get {
  108. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
  109. }
  110. }
  111. public Boolean IsFamilyOrAssembly {
  112. get {
  113. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
  114. }
  115. }
  116. public Boolean IsStatic {
  117. get {
  118. return (Attributes & MethodAttributes.Static) != 0;
  119. }
  120. }
  121. public Boolean IsFinal {
  122. get {
  123. return (Attributes & MethodAttributes.Final) != 0;
  124. }
  125. }
  126. public Boolean IsVirtual {
  127. get {
  128. return (Attributes & MethodAttributes.Virtual) != 0;
  129. }
  130. }
  131. public Boolean IsHideBySig {
  132. get {
  133. return (Attributes & MethodAttributes.HideBySig) != 0;
  134. }
  135. }
  136. public Boolean IsAbstract {
  137. get {
  138. return (Attributes & MethodAttributes.Abstract) != 0;
  139. }
  140. }
  141. public Boolean IsSpecialName {
  142. get {
  143. int attr = (int)Attributes;
  144. return (attr & (int)MethodAttributes.SpecialName) != 0;
  145. }
  146. }
  147. [ComVisibleAttribute (true)]
  148. public Boolean IsConstructor {
  149. get {
  150. int attr = (int)Attributes;
  151. return ((attr & (int)MethodAttributes.RTSpecialName) != 0
  152. && (Name == ".ctor"));
  153. }
  154. }
  155. internal virtual int get_next_table_index (object obj, int table, bool inc) {
  156. if (this is MethodBuilder) {
  157. MethodBuilder mb = (MethodBuilder)this;
  158. return mb.get_next_table_index (obj, table, inc);
  159. }
  160. if (this is ConstructorBuilder) {
  161. ConstructorBuilder mb = (ConstructorBuilder)this;
  162. return mb.get_next_table_index (obj, table, inc);
  163. }
  164. throw new Exception ("Method is not a builder method");
  165. }
  166. #if NET_2_0 || BOOTSTRAP_NET_2_0
  167. [ComVisible (true)]
  168. public virtual Type [] GetGenericArguments ()
  169. {
  170. throw new NotSupportedException ();
  171. }
  172. public virtual bool ContainsGenericParameters {
  173. get {
  174. return false;
  175. }
  176. }
  177. public virtual bool IsGenericMethodDefinition {
  178. get {
  179. return false;
  180. }
  181. }
  182. public virtual bool IsGenericMethod {
  183. get {
  184. return false;
  185. }
  186. }
  187. #endif
  188. #if NET_2_0
  189. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  190. internal extern static MethodBody GetMethodBodyInternal (IntPtr handle);
  191. internal static MethodBody GetMethodBody (IntPtr handle) {
  192. return GetMethodBodyInternal (handle);
  193. }
  194. public virtual MethodBody GetMethodBody () {
  195. throw new NotSupportedException ();
  196. }
  197. #endif
  198. void _MethodBase.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
  199. {
  200. throw new NotImplementedException ();
  201. }
  202. void _MethodBase.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
  203. {
  204. throw new NotImplementedException ();
  205. }
  206. void _MethodBase.GetTypeInfoCount (out uint pcTInfo)
  207. {
  208. throw new NotImplementedException ();
  209. }
  210. void _MethodBase.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
  211. {
  212. throw new NotImplementedException ();
  213. }
  214. }
  215. }