MethodBase.cs 5.5 KB

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