MonoMethod.cs 4.9 KB

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