MonoMethod.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. //
  2. // MonoMethod.cs: The class used to represent methods from the mono runtime.
  3. //
  4. // Authors:
  5. // Paolo Molaro ([email protected])
  6. // Marek Safar ([email protected])
  7. //
  8. // (C) 2001 Ximian, Inc. http://www.ximian.com
  9. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  10. // Copyright (C) 2012 Xamarin Inc (http://www.xamarin.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using System.Collections.Generic;
  32. using System.Globalization;
  33. using System.Runtime.CompilerServices;
  34. using System.Runtime.InteropServices;
  35. using System.Runtime.Serialization;
  36. #if !FULL_AOT_RUNTIME
  37. using System.Reflection.Emit;
  38. #endif
  39. using System.Security;
  40. using System.Threading;
  41. using System.Text;
  42. using System.Diagnostics;
  43. using System.Diagnostics.Contracts;
  44. namespace System.Reflection {
  45. internal struct MonoMethodInfo
  46. {
  47. #pragma warning disable 649
  48. private Type parent;
  49. private Type ret;
  50. internal MethodAttributes attrs;
  51. internal MethodImplAttributes iattrs;
  52. private CallingConventions callconv;
  53. #pragma warning restore 649
  54. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  55. static extern void get_method_info (IntPtr handle, out MonoMethodInfo info);
  56. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  57. static extern int get_method_attributes (IntPtr handle);
  58. internal static MonoMethodInfo GetMethodInfo (IntPtr handle)
  59. {
  60. MonoMethodInfo info;
  61. MonoMethodInfo.get_method_info (handle, out info);
  62. return info;
  63. }
  64. internal static Type GetDeclaringType (IntPtr handle)
  65. {
  66. return GetMethodInfo (handle).parent;
  67. }
  68. internal static Type GetReturnType (IntPtr handle)
  69. {
  70. return GetMethodInfo (handle).ret;
  71. }
  72. internal static MethodAttributes GetAttributes (IntPtr handle)
  73. {
  74. return (MethodAttributes)get_method_attributes (handle);
  75. }
  76. internal static CallingConventions GetCallingConvention (IntPtr handle)
  77. {
  78. return GetMethodInfo (handle).callconv;
  79. }
  80. internal static MethodImplAttributes GetMethodImplementationFlags (IntPtr handle)
  81. {
  82. return GetMethodInfo (handle).iattrs;
  83. }
  84. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  85. static extern ParameterInfo[] get_parameter_info (IntPtr handle, MemberInfo member);
  86. static internal ParameterInfo[] GetParametersInfo (IntPtr handle, MemberInfo member)
  87. {
  88. return get_parameter_info (handle, member);
  89. }
  90. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  91. static extern MarshalAsAttribute get_retval_marshal (IntPtr handle);
  92. static internal ParameterInfo GetReturnParameterInfo (MonoMethod method)
  93. {
  94. return ParameterInfo.New (GetReturnType (method.mhandle), method, get_retval_marshal (method.mhandle));
  95. }
  96. };
  97. abstract class RuntimeMethodInfo : MethodInfo, ISerializable
  98. {
  99. internal BindingFlags BindingFlags {
  100. get {
  101. return 0;
  102. }
  103. }
  104. public override Module Module {
  105. get {
  106. return GetRuntimeModule ();
  107. }
  108. }
  109. RuntimeType ReflectedTypeInternal {
  110. get {
  111. return (RuntimeType) ReflectedType;
  112. }
  113. }
  114. internal override string FormatNameAndSig (bool serialization)
  115. {
  116. // Serialization uses ToString to resolve MethodInfo overloads.
  117. StringBuilder sbName = new StringBuilder(Name);
  118. // serialization == true: use unambiguous (except for assembly name) type names to distinguish between overloads.
  119. // serialization == false: use basic format to maintain backward compatibility of MethodInfo.ToString().
  120. TypeNameFormatFlags format = serialization ? TypeNameFormatFlags.FormatSerialization : TypeNameFormatFlags.FormatBasic;
  121. if (IsGenericMethod)
  122. sbName.Append(RuntimeMethodHandle.ConstructInstantiation(this, format));
  123. sbName.Append("(");
  124. ParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention, serialization);
  125. sbName.Append(")");
  126. return sbName.ToString();
  127. }
  128. public override String ToString()
  129. {
  130. return ReturnType.FormatTypeName() + " " + FormatNameAndSig(false);
  131. }
  132. internal RuntimeModule GetRuntimeModule ()
  133. {
  134. return ((RuntimeType)DeclaringType).GetRuntimeModule();
  135. }
  136. #region ISerializable Implementation
  137. public void GetObjectData(SerializationInfo info, StreamingContext context)
  138. {
  139. if (info == null)
  140. throw new ArgumentNullException("info");
  141. Contract.EndContractBlock();
  142. MemberInfoSerializationHolder.GetSerializationInfo(
  143. info,
  144. Name,
  145. ReflectedTypeInternal,
  146. ToString(),
  147. SerializationToString(),
  148. MemberTypes.Method,
  149. IsGenericMethod & !IsGenericMethodDefinition ? GetGenericArguments() : null);
  150. }
  151. internal string SerializationToString()
  152. {
  153. return ReturnType.FormatTypeName(true) + " " + FormatNameAndSig(true);
  154. }
  155. #endregion
  156. }
  157. /*
  158. * Note: most of this class needs to be duplicated for the contructor, since
  159. * the .NET reflection class hierarchy is so broken.
  160. */
  161. [Serializable()]
  162. [StructLayout (LayoutKind.Sequential)]
  163. internal class MonoMethod : RuntimeMethodInfo
  164. {
  165. #pragma warning disable 649
  166. internal IntPtr mhandle;
  167. string name;
  168. Type reftype;
  169. #pragma warning restore 649
  170. internal MonoMethod () {
  171. }
  172. internal MonoMethod (RuntimeMethodHandle mhandle) {
  173. this.mhandle = mhandle.Value;
  174. }
  175. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  176. internal static extern string get_name (MethodBase method);
  177. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  178. internal static extern MonoMethod get_base_method (MonoMethod method, bool definition);
  179. public override MethodInfo GetBaseDefinition ()
  180. {
  181. return get_base_method (this, true);
  182. }
  183. internal override MethodInfo GetBaseMethod ()
  184. {
  185. return get_base_method (this, false);
  186. }
  187. public override ParameterInfo ReturnParameter {
  188. get {
  189. return MonoMethodInfo.GetReturnParameterInfo (this);
  190. }
  191. }
  192. public override Type ReturnType {
  193. get {
  194. return MonoMethodInfo.GetReturnType (mhandle);
  195. }
  196. }
  197. public override ICustomAttributeProvider ReturnTypeCustomAttributes {
  198. get {
  199. return MonoMethodInfo.GetReturnParameterInfo (this);
  200. }
  201. }
  202. public override MethodImplAttributes GetMethodImplementationFlags ()
  203. {
  204. return MonoMethodInfo.GetMethodImplementationFlags (mhandle);
  205. }
  206. public override ParameterInfo[] GetParameters ()
  207. {
  208. var src = MonoMethodInfo.GetParametersInfo (mhandle, this);
  209. if (src.Length == 0)
  210. return src;
  211. // Have to clone because GetParametersInfo icall returns cached value
  212. var dest = new ParameterInfo [src.Length];
  213. Array.FastCopy (src, 0, dest, 0, src.Length);
  214. return dest;
  215. }
  216. internal override ParameterInfo[] GetParametersInternal ()
  217. {
  218. return MonoMethodInfo.GetParametersInfo (mhandle, this);
  219. }
  220. internal override int GetParametersCount ()
  221. {
  222. return MonoMethodInfo.GetParametersInfo (mhandle, this).Length;
  223. }
  224. /*
  225. * InternalInvoke() receives the parameters correctly converted by the
  226. * binder to match the types of the method signature.
  227. */
  228. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  229. internal extern Object InternalInvoke (Object obj, Object[] parameters, out Exception exc);
  230. [DebuggerHidden]
  231. [DebuggerStepThrough]
  232. public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  233. {
  234. if (binder == null)
  235. binder = Type.DefaultBinder;
  236. /*Avoid allocating an array every time*/
  237. ParameterInfo[] pinfo = GetParametersInternal ();
  238. ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
  239. if (ContainsGenericParameters)
  240. throw new InvalidOperationException ("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.");
  241. Exception exc;
  242. object o = null;
  243. try {
  244. // The ex argument is used to distinguish exceptions thrown by the icall
  245. // from the exceptions thrown by the called method (which need to be
  246. // wrapped in TargetInvocationException).
  247. o = InternalInvoke (obj, parameters, out exc);
  248. } catch (ThreadAbortException) {
  249. throw;
  250. #if NET_2_1
  251. } catch (MethodAccessException) {
  252. throw;
  253. #endif
  254. } catch (Exception e) {
  255. throw new TargetInvocationException (e);
  256. }
  257. if (exc != null)
  258. throw exc;
  259. return o;
  260. }
  261. internal static void ConvertValues (Binder binder, object[] args, ParameterInfo[] pinfo, CultureInfo culture, BindingFlags invokeAttr)
  262. {
  263. if (args == null) {
  264. if (pinfo.Length == 0)
  265. return;
  266. throw new TargetParameterCountException ();
  267. }
  268. if (pinfo.Length != args.Length)
  269. throw new TargetParameterCountException ();
  270. for (int i = 0; i < args.Length; ++i) {
  271. var arg = args [i];
  272. var pi = pinfo [i];
  273. if (arg == Type.Missing) {
  274. if (pi.DefaultValue == System.DBNull.Value)
  275. throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"),"parameters");
  276. args [i] = pi.DefaultValue;
  277. continue;
  278. }
  279. var rt = (RuntimeType) pi.ParameterType;
  280. args [i] = rt.CheckValue (arg, binder, culture, invokeAttr);
  281. }
  282. }
  283. public override RuntimeMethodHandle MethodHandle {
  284. get {
  285. return new RuntimeMethodHandle (mhandle);
  286. }
  287. }
  288. public override MethodAttributes Attributes {
  289. get {
  290. return MonoMethodInfo.GetAttributes (mhandle);
  291. }
  292. }
  293. public override CallingConventions CallingConvention {
  294. get {
  295. return MonoMethodInfo.GetCallingConvention (mhandle);
  296. }
  297. }
  298. public override Type ReflectedType {
  299. get {
  300. return reftype;
  301. }
  302. }
  303. public override Type DeclaringType {
  304. get {
  305. return MonoMethodInfo.GetDeclaringType (mhandle);
  306. }
  307. }
  308. public override string Name {
  309. get {
  310. if (name != null)
  311. return name;
  312. return get_name (this);
  313. }
  314. }
  315. public override bool IsDefined (Type attributeType, bool inherit) {
  316. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  317. }
  318. public override object[] GetCustomAttributes( bool inherit) {
  319. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  320. }
  321. public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
  322. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  323. }
  324. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  325. internal extern void GetPInvoke (out PInvokeAttributes flags, out string entryPoint, out string dllName);
  326. internal object[] GetPseudoCustomAttributes ()
  327. {
  328. int count = 0;
  329. /* MS.NET doesn't report MethodImplAttribute */
  330. MonoMethodInfo info = MonoMethodInfo.GetMethodInfo (mhandle);
  331. if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
  332. count ++;
  333. if ((info.attrs & MethodAttributes.PinvokeImpl) != 0)
  334. count ++;
  335. if (count == 0)
  336. return null;
  337. object[] attrs = new object [count];
  338. count = 0;
  339. if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
  340. attrs [count ++] = new PreserveSigAttribute ();
  341. if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) {
  342. attrs [count ++] = DllImportAttribute.GetCustomAttribute (this);
  343. }
  344. return attrs;
  345. }
  346. public override MethodInfo MakeGenericMethod (Type [] methodInstantiation)
  347. {
  348. if (methodInstantiation == null)
  349. throw new ArgumentNullException ("methodInstantiation");
  350. if (!IsGenericMethodDefinition)
  351. throw new InvalidOperationException ("not a generic method definition");
  352. /*FIXME add GetGenericArgumentsLength() internal vcall to speed this up*/
  353. if (GetGenericArguments ().Length != methodInstantiation.Length)
  354. throw new ArgumentException ("Incorrect length");
  355. bool hasUserType = false;
  356. foreach (Type type in methodInstantiation) {
  357. if (type == null)
  358. throw new ArgumentNullException ();
  359. if (!(type is MonoType))
  360. hasUserType = true;
  361. }
  362. if (hasUserType)
  363. #if FULL_AOT_RUNTIME
  364. throw new NotSupportedException ("User types are not supported under full aot");
  365. #else
  366. return new MethodOnTypeBuilderInst (this, methodInstantiation);
  367. #endif
  368. MethodInfo ret = MakeGenericMethod_impl (methodInstantiation);
  369. if (ret == null)
  370. throw new ArgumentException (String.Format ("The method has {0} generic parameter(s) but {1} generic argument(s) were provided.", GetGenericArguments ().Length, methodInstantiation.Length));
  371. return ret;
  372. }
  373. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  374. extern MethodInfo MakeGenericMethod_impl (Type [] types);
  375. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  376. public override extern Type [] GetGenericArguments ();
  377. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  378. extern MethodInfo GetGenericMethodDefinition_impl ();
  379. public override MethodInfo GetGenericMethodDefinition ()
  380. {
  381. MethodInfo res = GetGenericMethodDefinition_impl ();
  382. if (res == null)
  383. throw new InvalidOperationException ();
  384. return res;
  385. }
  386. public override extern bool IsGenericMethodDefinition {
  387. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  388. get;
  389. }
  390. public override extern bool IsGenericMethod {
  391. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  392. get;
  393. }
  394. public override bool ContainsGenericParameters {
  395. get {
  396. if (IsGenericMethod) {
  397. foreach (Type arg in GetGenericArguments ())
  398. if (arg.ContainsGenericParameters)
  399. return true;
  400. }
  401. return DeclaringType.ContainsGenericParameters;
  402. }
  403. }
  404. public override MethodBody GetMethodBody () {
  405. return GetMethodBody (mhandle);
  406. }
  407. public override IList<CustomAttributeData> GetCustomAttributesData () {
  408. return CustomAttributeData.GetCustomAttributes (this);
  409. }
  410. //seclevel { transparent = 0, safe-critical = 1, critical = 2}
  411. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  412. public extern int get_core_clr_security_level ();
  413. public override bool IsSecurityTransparent {
  414. get { return get_core_clr_security_level () == 0; }
  415. }
  416. public override bool IsSecurityCritical {
  417. get { return get_core_clr_security_level () > 0; }
  418. }
  419. public override bool IsSecuritySafeCritical {
  420. get { return get_core_clr_security_level () == 1; }
  421. }
  422. }
  423. abstract class RuntimeConstructorInfo : ConstructorInfo, ISerializable
  424. {
  425. public override Module Module {
  426. get {
  427. return GetRuntimeModule ();
  428. }
  429. }
  430. internal RuntimeModule GetRuntimeModule ()
  431. {
  432. return RuntimeTypeHandle.GetModule((RuntimeType)DeclaringType);
  433. }
  434. internal BindingFlags BindingFlags {
  435. get {
  436. return 0;
  437. }
  438. }
  439. RuntimeType ReflectedTypeInternal {
  440. get {
  441. return (RuntimeType) ReflectedType;
  442. }
  443. }
  444. #region ISerializable Implementation
  445. public void GetObjectData(SerializationInfo info, StreamingContext context)
  446. {
  447. if (info == null)
  448. throw new ArgumentNullException("info");
  449. Contract.EndContractBlock();
  450. MemberInfoSerializationHolder.GetSerializationInfo(
  451. info,
  452. Name,
  453. ReflectedTypeInternal,
  454. ToString(),
  455. SerializationToString(),
  456. MemberTypes.Constructor,
  457. null);
  458. }
  459. internal string SerializationToString()
  460. {
  461. // We don't need the return type for constructors.
  462. return FormatNameAndSig(true);
  463. }
  464. internal void SerializationInvoke (Object target, SerializationInfo info, StreamingContext context)
  465. {
  466. Invoke (target, new object[] { info, context });
  467. }
  468. #endregion
  469. }
  470. [Serializable()]
  471. [StructLayout (LayoutKind.Sequential)]
  472. internal class MonoCMethod : RuntimeConstructorInfo
  473. {
  474. #pragma warning disable 649
  475. internal IntPtr mhandle;
  476. string name;
  477. Type reftype;
  478. #pragma warning restore 649
  479. public override MethodImplAttributes GetMethodImplementationFlags ()
  480. {
  481. return MonoMethodInfo.GetMethodImplementationFlags (mhandle);
  482. }
  483. public override ParameterInfo[] GetParameters ()
  484. {
  485. return MonoMethodInfo.GetParametersInfo (mhandle, this);
  486. }
  487. internal override ParameterInfo[] GetParametersInternal ()
  488. {
  489. return MonoMethodInfo.GetParametersInfo (mhandle, this);
  490. }
  491. internal override int GetParametersCount ()
  492. {
  493. var pi = MonoMethodInfo.GetParametersInfo (mhandle, this);
  494. return pi == null ? 0 : pi.Length;
  495. }
  496. /*
  497. * InternalInvoke() receives the parameters correctly converted by the binder
  498. * to match the types of the method signature.
  499. */
  500. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  501. internal extern Object InternalInvoke (Object obj, Object[] parameters, out Exception exc);
  502. [DebuggerHidden]
  503. [DebuggerStepThrough]
  504. public override object Invoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
  505. {
  506. if (obj == null) {
  507. if (!IsStatic)
  508. throw new TargetException ("Instance constructor requires a target");
  509. } else if (!DeclaringType.IsInstanceOfType (obj)) {
  510. throw new TargetException ("Constructor does not match target type");
  511. }
  512. return DoInvoke (obj, invokeAttr, binder, parameters, culture);
  513. }
  514. object DoInvoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
  515. {
  516. if (binder == null)
  517. binder = Type.DefaultBinder;
  518. ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo (mhandle, this);
  519. MonoMethod.ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
  520. if (obj == null && DeclaringType.ContainsGenericParameters)
  521. throw new MemberAccessException ("Cannot create an instance of " + DeclaringType + " because Type.ContainsGenericParameters is true.");
  522. if ((invokeAttr & BindingFlags.CreateInstance) != 0 && DeclaringType.IsAbstract) {
  523. throw new MemberAccessException (String.Format ("Cannot create an instance of {0} because it is an abstract class", DeclaringType));
  524. }
  525. return InternalInvoke (obj, parameters);
  526. }
  527. public object InternalInvoke (object obj, object[] parameters)
  528. {
  529. Exception exc;
  530. object o = null;
  531. try {
  532. o = InternalInvoke (obj, parameters, out exc);
  533. #if NET_2_1
  534. } catch (MethodAccessException) {
  535. throw;
  536. #endif
  537. } catch (Exception e) {
  538. throw new TargetInvocationException (e);
  539. }
  540. if (exc != null)
  541. throw exc;
  542. return obj == null ? o : null;
  543. }
  544. [DebuggerHidden]
  545. [DebuggerStepThrough]
  546. public override Object Invoke (BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  547. {
  548. return DoInvoke (null, invokeAttr, binder, parameters, culture);
  549. }
  550. public override RuntimeMethodHandle MethodHandle {
  551. get {
  552. return new RuntimeMethodHandle (mhandle);
  553. }
  554. }
  555. public override MethodAttributes Attributes {
  556. get {
  557. return MonoMethodInfo.GetAttributes (mhandle);
  558. }
  559. }
  560. public override CallingConventions CallingConvention {
  561. get {
  562. return MonoMethodInfo.GetCallingConvention (mhandle);
  563. }
  564. }
  565. public override bool ContainsGenericParameters {
  566. get {
  567. return DeclaringType.ContainsGenericParameters;
  568. }
  569. }
  570. public override Type ReflectedType {
  571. get {
  572. return reftype;
  573. }
  574. }
  575. public override Type DeclaringType {
  576. get {
  577. return MonoMethodInfo.GetDeclaringType (mhandle);
  578. }
  579. }
  580. public override string Name {
  581. get {
  582. if (name != null)
  583. return name;
  584. return MonoMethod.get_name (this);
  585. }
  586. }
  587. public override bool IsDefined (Type attributeType, bool inherit) {
  588. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  589. }
  590. public override object[] GetCustomAttributes( bool inherit) {
  591. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  592. }
  593. public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
  594. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  595. }
  596. public override MethodBody GetMethodBody () {
  597. return GetMethodBody (mhandle);
  598. }
  599. public override string ToString () {
  600. StringBuilder sb = new StringBuilder ();
  601. sb.Append ("Void ");
  602. sb.Append (Name);
  603. sb.Append ("(");
  604. ParameterInfo[] p = GetParameters ();
  605. for (int i = 0; i < p.Length; ++i) {
  606. if (i > 0)
  607. sb.Append (", ");
  608. sb.Append (p[i].ParameterType.Name);
  609. }
  610. if (CallingConvention == CallingConventions.Any)
  611. sb.Append (", ...");
  612. sb.Append (")");
  613. return sb.ToString ();
  614. }
  615. public override IList<CustomAttributeData> GetCustomAttributesData () {
  616. return CustomAttributeData.GetCustomAttributes (this);
  617. }
  618. }
  619. }