MonoMethod.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. //
  2. // System.Reflection/MonoMethod.cs
  3. // The class used to represent methods from the mono runtime.
  4. //
  5. // Author:
  6. // Paolo Molaro ([email protected])
  7. //
  8. // (C) 2001 Ximian, Inc. http://www.ximian.com
  9. //
  10. using System;
  11. using System.Globalization;
  12. using System.Runtime.CompilerServices;
  13. using System.Runtime.InteropServices;
  14. namespace System.Reflection {
  15. internal struct MonoMethodInfo {
  16. internal Type parent;
  17. internal Type ret;
  18. internal MethodAttributes attrs;
  19. internal MethodImplAttributes iattrs;
  20. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  21. internal static extern void get_method_info (RuntimeMethodHandle handle, out MonoMethodInfo info);
  22. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  23. internal static extern ParameterInfo[] get_parameter_info (RuntimeMethodHandle handle);
  24. };
  25. /*
  26. * Note: most of this class needs to be duplicated for the contructor, since
  27. * the .NET reflection class hierarchy is so broken.
  28. */
  29. internal class MonoMethod : MethodInfo {
  30. internal RuntimeMethodHandle mhandle;
  31. string name;
  32. [MonoTODO]
  33. public override MethodInfo GetBaseDefinition() {
  34. return this; /* FIXME */
  35. }
  36. public override Type ReturnType {
  37. get {
  38. MonoMethodInfo info;
  39. MonoMethodInfo.get_method_info (mhandle, out info);
  40. return info.ret;
  41. }
  42. }
  43. public override ICustomAttributeProvider ReturnTypeCustomAttributes {
  44. get {return null;}
  45. }
  46. public override MethodImplAttributes GetMethodImplementationFlags() {
  47. MonoMethodInfo info;
  48. MonoMethodInfo.get_method_info (mhandle, out info);
  49. return info.iattrs;
  50. }
  51. public override ParameterInfo[] GetParameters() {
  52. return MonoMethodInfo.get_parameter_info (mhandle);
  53. }
  54. /*
  55. * InternalInvoke() receives the parameters corretcly converted by the binder
  56. * to match the types of the method signature.
  57. */
  58. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  59. internal extern Object InternalInvoke (Object obj, Object[] parameters);
  60. [MonoTODO]
  61. public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
  62. // fixme: consider all other parameters
  63. return InternalInvoke (obj, parameters);
  64. }
  65. public override RuntimeMethodHandle MethodHandle {
  66. get {return mhandle;}
  67. }
  68. public override MethodAttributes Attributes {
  69. get {
  70. MonoMethodInfo info;
  71. MonoMethodInfo.get_method_info (mhandle, out info);
  72. return info.attrs;
  73. }
  74. }
  75. public override Type ReflectedType {
  76. get {
  77. MonoMethodInfo info;
  78. MonoMethodInfo.get_method_info (mhandle, out info);
  79. return info.parent;
  80. }
  81. }
  82. public override Type DeclaringType {
  83. get {
  84. MonoMethodInfo info;
  85. MonoMethodInfo.get_method_info (mhandle, out info);
  86. return info.parent;
  87. }
  88. }
  89. public override string Name {
  90. get {
  91. return name;
  92. }
  93. }
  94. public override bool IsDefined (Type attributeType, bool inherit) {
  95. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  96. }
  97. public override object[] GetCustomAttributes( bool inherit) {
  98. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  99. }
  100. public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
  101. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  102. }
  103. public override string ToString () {
  104. string parms = "";
  105. ParameterInfo[] p = GetParameters ();
  106. for (int i = 0; i < p.Length; ++i) {
  107. if (i > 0)
  108. parms = parms + ", ";
  109. parms = parms + p [i].ParameterType.Name;
  110. }
  111. return ReturnType.Name+" "+Name+"("+parms+")";
  112. }
  113. }
  114. internal class MonoCMethod : ConstructorInfo {
  115. internal RuntimeMethodHandle mhandle;
  116. string name;
  117. public override MethodImplAttributes GetMethodImplementationFlags() {
  118. MonoMethodInfo info;
  119. MonoMethodInfo.get_method_info (mhandle, out info);
  120. return info.iattrs;
  121. }
  122. public override ParameterInfo[] GetParameters() {
  123. return MonoMethodInfo.get_parameter_info (mhandle);
  124. }
  125. /*
  126. * InternalInvoke() receives the parameters corretcly converted by the binder
  127. * to match the types of the method signature.
  128. */
  129. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  130. internal extern Object InternalInvoke (Object obj, Object[] parameters);
  131. public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
  132. throw new NotImplementedException ();
  133. }
  134. public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
  135. return InternalInvoke (null, parameters);
  136. }
  137. public override RuntimeMethodHandle MethodHandle {
  138. get {return mhandle;}
  139. }
  140. public override MethodAttributes Attributes {
  141. get {
  142. MonoMethodInfo info;
  143. MonoMethodInfo.get_method_info (mhandle, out info);
  144. return info.attrs;
  145. }
  146. }
  147. public override Type ReflectedType {
  148. get {
  149. MonoMethodInfo info;
  150. MonoMethodInfo.get_method_info (mhandle, out info);
  151. return info.parent;
  152. }
  153. }
  154. public override Type DeclaringType {
  155. get {
  156. MonoMethodInfo info;
  157. MonoMethodInfo.get_method_info (mhandle, out info);
  158. return info.parent;
  159. }
  160. }
  161. public override string Name {
  162. get {
  163. return name;
  164. }
  165. }
  166. [MonoTODO]
  167. public override bool IsDefined (Type attribute_type, bool inherit) {
  168. return false;
  169. }
  170. [MonoTODO]
  171. public override object[] GetCustomAttributes (bool inherit) {
  172. return null;
  173. }
  174. [MonoTODO]
  175. public override object[] GetCustomAttributes (Type attributeType, bool inherit) {
  176. return null;
  177. }
  178. }
  179. }