2
0

MonoMethod.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 string name;
  19. internal MethodAttributes attrs;
  20. internal MethodImplAttributes iattrs;
  21. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  22. internal static extern void get_method_info (RuntimeMethodHandle handle, out MonoMethodInfo info);
  23. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  24. internal static extern ParameterInfo[] get_parameter_info (RuntimeMethodHandle handle);
  25. };
  26. /*
  27. * Note: most of this class needs to be duplicated for the contructor, since
  28. * the .NET reflection class hierarchy is so broken.
  29. */
  30. internal class MonoMethod : MethodInfo {
  31. internal RuntimeMethodHandle mhandle;
  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. MonoMethodInfo info;
  92. MonoMethodInfo.get_method_info (mhandle, out info);
  93. return info.name;
  94. }
  95. }
  96. public override bool IsDefined (Type attributeType, bool inherit) {
  97. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  98. }
  99. public override object[] GetCustomAttributes( bool inherit) {
  100. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  101. }
  102. public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
  103. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  104. }
  105. public override string ToString () {
  106. string parms = "";
  107. ParameterInfo[] p = GetParameters ();
  108. for (int i = 0; i < p.Length; ++i) {
  109. if (i > 0)
  110. parms = parms + ", ";
  111. parms = parms + p [i].ParameterType.Name;
  112. }
  113. return ReturnType.Name+" "+Name+"("+parms+")";
  114. }
  115. }
  116. internal class MonoCMethod : ConstructorInfo {
  117. internal RuntimeMethodHandle mhandle;
  118. public override MethodImplAttributes GetMethodImplementationFlags() {
  119. MonoMethodInfo info;
  120. MonoMethodInfo.get_method_info (mhandle, out info);
  121. return info.iattrs;
  122. }
  123. public override ParameterInfo[] GetParameters() {
  124. return MonoMethodInfo.get_parameter_info (mhandle);
  125. }
  126. public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
  127. throw new NotImplementedException ();
  128. }
  129. public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
  130. throw new NotImplementedException ();
  131. }
  132. public override RuntimeMethodHandle MethodHandle {
  133. get {return mhandle;}
  134. }
  135. public override MethodAttributes Attributes {
  136. get {
  137. MonoMethodInfo info;
  138. MonoMethodInfo.get_method_info (mhandle, out info);
  139. return info.attrs;
  140. }
  141. }
  142. public override Type ReflectedType {
  143. get {
  144. MonoMethodInfo info;
  145. MonoMethodInfo.get_method_info (mhandle, out info);
  146. return info.parent;
  147. }
  148. }
  149. public override Type DeclaringType {
  150. get {
  151. MonoMethodInfo info;
  152. MonoMethodInfo.get_method_info (mhandle, out info);
  153. return info.parent;
  154. }
  155. }
  156. public override string Name {
  157. get {
  158. MonoMethodInfo info;
  159. MonoMethodInfo.get_method_info (mhandle, out info);
  160. return info.name;
  161. }
  162. }
  163. [MonoTODO]
  164. public override bool IsDefined (Type attribute_type, bool inherit) {
  165. return false;
  166. }
  167. [MonoTODO]
  168. public override object[] GetCustomAttributes (bool inherit) {
  169. return null;
  170. }
  171. [MonoTODO]
  172. public override object[] GetCustomAttributes (Type attributeType, bool inherit) {
  173. return null;
  174. }
  175. }
  176. }