MethodBase.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. using System;
  10. using System.Globalization;
  11. using System.Reflection.Emit;
  12. using System.Runtime.CompilerServices;
  13. using System.Runtime.InteropServices;
  14. namespace System.Reflection {
  15. [Serializable]
  16. [ClassInterface(ClassInterfaceType.AutoDual)]
  17. public abstract class MethodBase: MemberInfo {
  18. [MethodImplAttribute (MethodImplOptions.InternalCall)]
  19. public extern static MethodBase GetCurrentMethod ();
  20. public static MethodBase GetMethodFromHandle(RuntimeMethodHandle handle)
  21. {
  22. return null;
  23. }
  24. public abstract MethodImplAttributes GetMethodImplementationFlags();
  25. public abstract ParameterInfo[] GetParameters();
  26. //
  27. // This is a quick version for our own use. We should override
  28. // it where possible so that it does not allocate an array.
  29. //
  30. internal virtual int GetParameterCount ()
  31. {
  32. ParameterInfo [] pi = GetParameters ();
  33. if (pi == null)
  34. return 0;
  35. return pi.Length;
  36. }
  37. #if NET_1_2
  38. virtual
  39. #endif
  40. public Object Invoke(Object obj, Object[] parameters) {
  41. return Invoke (obj, 0, null, parameters, null);
  42. }
  43. public abstract Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture);
  44. protected MethodBase()
  45. {
  46. }
  47. public abstract RuntimeMethodHandle MethodHandle { get; }
  48. public abstract MethodAttributes Attributes { get; }
  49. public virtual CallingConventions CallingConvention { get {return CallingConventions.Standard;} }
  50. public Boolean IsPublic {
  51. get {
  52. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Public;
  53. }
  54. }
  55. public Boolean IsPrivate {
  56. get {
  57. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Private;
  58. }
  59. }
  60. public Boolean IsFamily {
  61. get {
  62. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Family;
  63. }
  64. }
  65. public Boolean IsAssembly {
  66. get {
  67. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.Assembly;
  68. }
  69. }
  70. public Boolean IsFamilyAndAssembly {
  71. get {
  72. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamANDAssem;
  73. }
  74. }
  75. public Boolean IsFamilyOrAssembly {
  76. get {
  77. return (Attributes & MethodAttributes.MemberAccessMask) == MethodAttributes.FamORAssem;
  78. }
  79. }
  80. public Boolean IsStatic {
  81. get {
  82. return (Attributes & MethodAttributes.Static) != 0;
  83. }
  84. }
  85. public Boolean IsFinal {
  86. get {
  87. return (Attributes & MethodAttributes.Final) != 0;
  88. }
  89. }
  90. public Boolean IsVirtual {
  91. get {
  92. return (Attributes & MethodAttributes.Virtual) != 0;
  93. }
  94. }
  95. public Boolean IsHideBySig {
  96. get {
  97. return (Attributes & MethodAttributes.HideBySig) != 0;
  98. }
  99. }
  100. public Boolean IsAbstract {
  101. get {
  102. return (Attributes & MethodAttributes.Abstract) != 0;
  103. }
  104. }
  105. public Boolean IsSpecialName {
  106. get {
  107. int attr = (int)Attributes;
  108. return (attr & (int)MethodAttributes.SpecialName) != 0;
  109. }
  110. }
  111. public Boolean IsConstructor {
  112. get {
  113. int attr = (int)Attributes;
  114. return ((attr & (int)MethodAttributes.RTSpecialName) != 0
  115. && (Name == ".ctor"));
  116. }
  117. }
  118. internal virtual int get_next_table_index (object obj, int table, bool inc) {
  119. if (this is MethodBuilder) {
  120. MethodBuilder mb = (MethodBuilder)this;
  121. return mb.get_next_table_index (obj, table, inc);
  122. }
  123. if (this is ConstructorBuilder) {
  124. ConstructorBuilder mb = (ConstructorBuilder)this;
  125. return mb.get_next_table_index (obj, table, inc);
  126. }
  127. throw new Exception ("Method is not a builder method");
  128. }
  129. }
  130. }