MonoMethod.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. throw new NotImplementedException ();
  63. }
  64. public override RuntimeMethodHandle MethodHandle {
  65. get {return mhandle;}
  66. }
  67. public override MethodAttributes Attributes {
  68. get {
  69. MonoMethodInfo info;
  70. MonoMethodInfo.get_method_info (mhandle, out info);
  71. return info.attrs;
  72. }
  73. }
  74. public override Type ReflectedType {
  75. get {
  76. MonoMethodInfo info;
  77. MonoMethodInfo.get_method_info (mhandle, out info);
  78. return info.parent;
  79. }
  80. }
  81. public override Type DeclaringType {
  82. get {
  83. MonoMethodInfo info;
  84. MonoMethodInfo.get_method_info (mhandle, out info);
  85. return info.parent;
  86. }
  87. }
  88. public override string Name {
  89. get {
  90. MonoMethodInfo info;
  91. MonoMethodInfo.get_method_info (mhandle, out info);
  92. return info.name;
  93. }
  94. }
  95. public override bool IsDefined (Type attributeType, bool inherit) {
  96. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  97. }
  98. public override object[] GetCustomAttributes( bool inherit) {
  99. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  100. }
  101. public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
  102. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  103. }
  104. public override string ToString () {
  105. string parms = "";
  106. ParameterInfo[] p = GetParameters ();
  107. for (int i = 0; i < p.Length; ++i) {
  108. if (i > 0)
  109. parms = parms + ", ";
  110. parms = parms + p [i].ParameterType.Name;
  111. }
  112. return Name+"("+parms+")";
  113. }
  114. }
  115. internal class MonoCMethod : ConstructorInfo {
  116. internal RuntimeMethodHandle mhandle;
  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. public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
  126. throw new NotImplementedException ();
  127. }
  128. public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
  129. throw new NotImplementedException ();
  130. }
  131. public override RuntimeMethodHandle MethodHandle {
  132. get {return mhandle;}
  133. }
  134. public override MethodAttributes Attributes {
  135. get {
  136. MonoMethodInfo info;
  137. MonoMethodInfo.get_method_info (mhandle, out info);
  138. return info.attrs;
  139. }
  140. }
  141. public override Type ReflectedType {
  142. get {
  143. MonoMethodInfo info;
  144. MonoMethodInfo.get_method_info (mhandle, out info);
  145. return info.parent;
  146. }
  147. }
  148. public override Type DeclaringType {
  149. get {
  150. MonoMethodInfo info;
  151. MonoMethodInfo.get_method_info (mhandle, out info);
  152. return info.parent;
  153. }
  154. }
  155. public override string Name {
  156. get {
  157. MonoMethodInfo info;
  158. MonoMethodInfo.get_method_info (mhandle, out info);
  159. return info.name;
  160. }
  161. }
  162. [MonoTODO]
  163. public override bool IsDefined (Type attribute_type, bool inherit) {
  164. return false;
  165. }
  166. [MonoTODO]
  167. public override object[] GetCustomAttributes (bool inherit) {
  168. return null;
  169. }
  170. [MonoTODO]
  171. public override object[] GetCustomAttributes (Type attributeType, bool inherit) {
  172. return null;
  173. }
  174. }
  175. }