MonoMethod.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  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. RuntimeType ReflectedTypeInternal {
  105. get {
  106. return (RuntimeType) ReflectedType;
  107. }
  108. }
  109. internal override string FormatNameAndSig (bool serialization)
  110. {
  111. // Serialization uses ToString to resolve MethodInfo overloads.
  112. StringBuilder sbName = new StringBuilder(Name);
  113. // serialization == true: use unambiguous (except for assembly name) type names to distinguish between overloads.
  114. // serialization == false: use basic format to maintain backward compatibility of MethodInfo.ToString().
  115. TypeNameFormatFlags format = serialization ? TypeNameFormatFlags.FormatSerialization : TypeNameFormatFlags.FormatBasic;
  116. if (IsGenericMethod)
  117. sbName.Append(RuntimeMethodHandle.ConstructInstantiation(this, format));
  118. sbName.Append("(");
  119. ParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention, serialization);
  120. sbName.Append(")");
  121. return sbName.ToString();
  122. }
  123. public override String ToString()
  124. {
  125. return ReturnType.FormatTypeName() + " " + FormatNameAndSig(false);
  126. }
  127. #region ISerializable Implementation
  128. public void GetObjectData(SerializationInfo info, StreamingContext context)
  129. {
  130. if (info == null)
  131. throw new ArgumentNullException("info");
  132. Contract.EndContractBlock();
  133. MemberInfoSerializationHolder.GetSerializationInfo(
  134. info,
  135. Name,
  136. ReflectedTypeInternal,
  137. ToString(),
  138. SerializationToString(),
  139. MemberTypes.Method,
  140. IsGenericMethod & !IsGenericMethodDefinition ? GetGenericArguments() : null);
  141. }
  142. internal string SerializationToString()
  143. {
  144. return ReturnType.FormatTypeName(true) + " " + FormatNameAndSig(true);
  145. }
  146. #endregion
  147. }
  148. /*
  149. * Note: most of this class needs to be duplicated for the contructor, since
  150. * the .NET reflection class hierarchy is so broken.
  151. */
  152. [Serializable()]
  153. [StructLayout (LayoutKind.Sequential)]
  154. internal class MonoMethod : RuntimeMethodInfo
  155. {
  156. #pragma warning disable 649
  157. internal IntPtr mhandle;
  158. string name;
  159. Type reftype;
  160. #pragma warning restore 649
  161. internal MonoMethod () {
  162. }
  163. internal MonoMethod (RuntimeMethodHandle mhandle) {
  164. this.mhandle = mhandle.Value;
  165. }
  166. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  167. internal static extern string get_name (MethodBase method);
  168. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  169. internal static extern MonoMethod get_base_method (MonoMethod method, bool definition);
  170. public override MethodInfo GetBaseDefinition ()
  171. {
  172. return get_base_method (this, true);
  173. }
  174. internal override MethodInfo GetBaseMethod ()
  175. {
  176. return get_base_method (this, false);
  177. }
  178. public override ParameterInfo ReturnParameter {
  179. get {
  180. return MonoMethodInfo.GetReturnParameterInfo (this);
  181. }
  182. }
  183. public override Type ReturnType {
  184. get {
  185. return MonoMethodInfo.GetReturnType (mhandle);
  186. }
  187. }
  188. public override ICustomAttributeProvider ReturnTypeCustomAttributes {
  189. get {
  190. return MonoMethodInfo.GetReturnParameterInfo (this);
  191. }
  192. }
  193. public override MethodImplAttributes GetMethodImplementationFlags ()
  194. {
  195. return MonoMethodInfo.GetMethodImplementationFlags (mhandle);
  196. }
  197. public override ParameterInfo[] GetParameters ()
  198. {
  199. var src = MonoMethodInfo.GetParametersInfo (mhandle, this);
  200. if (src.Length == 0)
  201. return src;
  202. // Have to clone because GetParametersInfo icall returns cached value
  203. var dest = new ParameterInfo [src.Length];
  204. Array.FastCopy (src, 0, dest, 0, src.Length);
  205. return dest;
  206. }
  207. internal override ParameterInfo[] GetParametersInternal ()
  208. {
  209. return MonoMethodInfo.GetParametersInfo (mhandle, this);
  210. }
  211. internal override int GetParametersCount ()
  212. {
  213. return MonoMethodInfo.GetParametersInfo (mhandle, this).Length;
  214. }
  215. /*
  216. * InternalInvoke() receives the parameters correctly converted by the
  217. * binder to match the types of the method signature.
  218. */
  219. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  220. internal extern Object InternalInvoke (Object obj, Object[] parameters, out Exception exc);
  221. [DebuggerHidden]
  222. [DebuggerStepThrough]
  223. public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  224. {
  225. if (binder == null)
  226. binder = Type.DefaultBinder;
  227. /*Avoid allocating an array every time*/
  228. ParameterInfo[] pinfo = GetParametersInternal ();
  229. ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
  230. #if !NET_2_1
  231. if (SecurityManager.SecurityEnabled) {
  232. // sadly Attributes doesn't tell us which kind of security action this is so
  233. // we must do it the hard way - and it also means that we can skip calling
  234. // Attribute (which is another an icall)
  235. SecurityManager.ReflectedLinkDemandInvoke (this);
  236. }
  237. #endif
  238. if (ContainsGenericParameters)
  239. throw new InvalidOperationException ("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.");
  240. Exception exc;
  241. object o = null;
  242. try {
  243. // The ex argument is used to distinguish exceptions thrown by the icall
  244. // from the exceptions thrown by the called method (which need to be
  245. // wrapped in TargetInvocationException).
  246. o = InternalInvoke (obj, parameters, out exc);
  247. } catch (ThreadAbortException) {
  248. throw;
  249. #if NET_2_1
  250. } catch (MethodAccessException) {
  251. throw;
  252. #endif
  253. } catch (Exception e) {
  254. throw new TargetInvocationException (e);
  255. }
  256. if (exc != null)
  257. throw exc;
  258. return o;
  259. }
  260. internal static void ConvertValues (Binder binder, object[] args, ParameterInfo[] pinfo, CultureInfo culture, BindingFlags invokeAttr)
  261. {
  262. if (args == null) {
  263. if (pinfo.Length == 0)
  264. return;
  265. throw new TargetParameterCountException ();
  266. }
  267. if (pinfo.Length != args.Length)
  268. throw new TargetParameterCountException ();
  269. for (int i = 0; i < args.Length; ++i) {
  270. var arg = args [i];
  271. var pi = pinfo [i];
  272. if (arg == Type.Missing) {
  273. if (pi.DefaultValue == System.DBNull.Value)
  274. throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"),"parameters");
  275. args [i] = pi.DefaultValue;
  276. continue;
  277. }
  278. var rt = (RuntimeType) pi.ParameterType;
  279. args [i] = rt.CheckValue (arg, binder, culture, invokeAttr);
  280. }
  281. }
  282. public override RuntimeMethodHandle MethodHandle {
  283. get {
  284. return new RuntimeMethodHandle (mhandle);
  285. }
  286. }
  287. public override MethodAttributes Attributes {
  288. get {
  289. return MonoMethodInfo.GetAttributes (mhandle);
  290. }
  291. }
  292. public override CallingConventions CallingConvention {
  293. get {
  294. return MonoMethodInfo.GetCallingConvention (mhandle);
  295. }
  296. }
  297. public override Type ReflectedType {
  298. get {
  299. return reftype;
  300. }
  301. }
  302. public override Type DeclaringType {
  303. get {
  304. return MonoMethodInfo.GetDeclaringType (mhandle);
  305. }
  306. }
  307. public override string Name {
  308. get {
  309. if (name != null)
  310. return name;
  311. return get_name (this);
  312. }
  313. }
  314. public override bool IsDefined (Type attributeType, bool inherit) {
  315. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  316. }
  317. public override object[] GetCustomAttributes( bool inherit) {
  318. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  319. }
  320. public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
  321. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  322. }
  323. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  324. internal static extern DllImportAttribute GetDllImportAttribute (IntPtr mhandle);
  325. internal object[] GetPseudoCustomAttributes ()
  326. {
  327. int count = 0;
  328. /* MS.NET doesn't report MethodImplAttribute */
  329. MonoMethodInfo info = MonoMethodInfo.GetMethodInfo (mhandle);
  330. if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
  331. count ++;
  332. if ((info.attrs & MethodAttributes.PinvokeImpl) != 0)
  333. count ++;
  334. if (count == 0)
  335. return null;
  336. object[] attrs = new object [count];
  337. count = 0;
  338. if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
  339. attrs [count ++] = new PreserveSigAttribute ();
  340. if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) {
  341. DllImportAttribute attr = GetDllImportAttribute (mhandle);
  342. if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
  343. attr.PreserveSig = true;
  344. attrs [count ++] = attr;
  345. }
  346. return attrs;
  347. }
  348. public override MethodInfo MakeGenericMethod (Type [] methodInstantiation)
  349. {
  350. if (methodInstantiation == null)
  351. throw new ArgumentNullException ("methodInstantiation");
  352. if (!IsGenericMethodDefinition)
  353. throw new InvalidOperationException ("not a generic method definition");
  354. /*FIXME add GetGenericArgumentsLength() internal vcall to speed this up*/
  355. if (GetGenericArguments ().Length != methodInstantiation.Length)
  356. throw new ArgumentException ("Incorrect length");
  357. bool hasUserType = false;
  358. foreach (Type type in methodInstantiation) {
  359. if (type == null)
  360. throw new ArgumentNullException ();
  361. if (!(type is MonoType))
  362. hasUserType = true;
  363. }
  364. if (hasUserType)
  365. #if FULL_AOT_RUNTIME
  366. throw new NotSupportedException ("User types are not supported under full aot");
  367. #else
  368. return new MethodOnTypeBuilderInst (this, methodInstantiation);
  369. #endif
  370. MethodInfo ret = MakeGenericMethod_impl (methodInstantiation);
  371. if (ret == null)
  372. throw new ArgumentException (String.Format ("The method has {0} generic parameter(s) but {1} generic argument(s) were provided.", GetGenericArguments ().Length, methodInstantiation.Length));
  373. return ret;
  374. }
  375. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  376. extern MethodInfo MakeGenericMethod_impl (Type [] types);
  377. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  378. public override extern Type [] GetGenericArguments ();
  379. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  380. extern MethodInfo GetGenericMethodDefinition_impl ();
  381. public override MethodInfo GetGenericMethodDefinition ()
  382. {
  383. MethodInfo res = GetGenericMethodDefinition_impl ();
  384. if (res == null)
  385. throw new InvalidOperationException ();
  386. return res;
  387. }
  388. public override extern bool IsGenericMethodDefinition {
  389. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  390. get;
  391. }
  392. public override extern bool IsGenericMethod {
  393. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  394. get;
  395. }
  396. public override bool ContainsGenericParameters {
  397. get {
  398. if (IsGenericMethod) {
  399. foreach (Type arg in GetGenericArguments ())
  400. if (arg.ContainsGenericParameters)
  401. return true;
  402. }
  403. return DeclaringType.ContainsGenericParameters;
  404. }
  405. }
  406. public override MethodBody GetMethodBody () {
  407. return GetMethodBody (mhandle);
  408. }
  409. public override IList<CustomAttributeData> GetCustomAttributesData () {
  410. return CustomAttributeData.GetCustomAttributes (this);
  411. }
  412. //seclevel { transparent = 0, safe-critical = 1, critical = 2}
  413. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  414. public extern int get_core_clr_security_level ();
  415. public override bool IsSecurityTransparent {
  416. get { return get_core_clr_security_level () == 0; }
  417. }
  418. public override bool IsSecurityCritical {
  419. get { return get_core_clr_security_level () > 0; }
  420. }
  421. public override bool IsSecuritySafeCritical {
  422. get { return get_core_clr_security_level () == 1; }
  423. }
  424. }
  425. abstract class RuntimeConstructorInfo : ConstructorInfo, ISerializable
  426. {
  427. public override Module Module {
  428. get {
  429. return GetRuntimeModule ();
  430. }
  431. }
  432. internal RuntimeModule GetRuntimeModule ()
  433. {
  434. return RuntimeTypeHandle.GetModule((RuntimeType)DeclaringType);
  435. }
  436. internal BindingFlags BindingFlags {
  437. get {
  438. return 0;
  439. }
  440. }
  441. RuntimeType ReflectedTypeInternal {
  442. get {
  443. return (RuntimeType) ReflectedType;
  444. }
  445. }
  446. #region ISerializable Implementation
  447. public void GetObjectData(SerializationInfo info, StreamingContext context)
  448. {
  449. if (info == null)
  450. throw new ArgumentNullException("info");
  451. Contract.EndContractBlock();
  452. MemberInfoSerializationHolder.GetSerializationInfo(
  453. info,
  454. Name,
  455. ReflectedTypeInternal,
  456. ToString(),
  457. SerializationToString(),
  458. MemberTypes.Constructor,
  459. null);
  460. }
  461. internal string SerializationToString()
  462. {
  463. // We don't need the return type for constructors.
  464. return FormatNameAndSig(true);
  465. }
  466. internal void SerializationInvoke (Object target, SerializationInfo info, StreamingContext context)
  467. {
  468. Invoke (target, new object[] { info, context });
  469. }
  470. #endregion
  471. }
  472. [Serializable()]
  473. [StructLayout (LayoutKind.Sequential)]
  474. internal class MonoCMethod : RuntimeConstructorInfo
  475. {
  476. #pragma warning disable 649
  477. internal IntPtr mhandle;
  478. string name;
  479. Type reftype;
  480. #pragma warning restore 649
  481. public override MethodImplAttributes GetMethodImplementationFlags ()
  482. {
  483. return MonoMethodInfo.GetMethodImplementationFlags (mhandle);
  484. }
  485. public override ParameterInfo[] GetParameters ()
  486. {
  487. return MonoMethodInfo.GetParametersInfo (mhandle, this);
  488. }
  489. internal override ParameterInfo[] GetParametersInternal ()
  490. {
  491. return MonoMethodInfo.GetParametersInfo (mhandle, this);
  492. }
  493. internal override int GetParametersCount ()
  494. {
  495. var pi = MonoMethodInfo.GetParametersInfo (mhandle, this);
  496. return pi == null ? 0 : pi.Length;
  497. }
  498. /*
  499. * InternalInvoke() receives the parameters correctly converted by the binder
  500. * to match the types of the method signature.
  501. */
  502. [MethodImplAttribute(MethodImplOptions.InternalCall)]
  503. internal extern Object InternalInvoke (Object obj, Object[] parameters, out Exception exc);
  504. [DebuggerHidden]
  505. [DebuggerStepThrough]
  506. public override object Invoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
  507. {
  508. if (obj == null) {
  509. if (!IsStatic)
  510. throw new TargetException ("Instance constructor requires a target");
  511. } else if (!DeclaringType.IsInstanceOfType (obj)) {
  512. throw new TargetException ("Constructor does not match target type");
  513. }
  514. return DoInvoke (obj, invokeAttr, binder, parameters, culture);
  515. }
  516. object DoInvoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
  517. {
  518. if (binder == null)
  519. binder = Type.DefaultBinder;
  520. ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo (mhandle, this);
  521. MonoMethod.ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
  522. #if !NET_2_1
  523. if (SecurityManager.SecurityEnabled) {
  524. // sadly Attributes doesn't tell us which kind of security action this is so
  525. // we must do it the hard way - and it also means that we can skip calling
  526. // Attribute (which is another an icall)
  527. SecurityManager.ReflectedLinkDemandInvoke (this);
  528. }
  529. #endif
  530. if (obj == null && DeclaringType.ContainsGenericParameters)
  531. throw new MemberAccessException ("Cannot create an instance of " + DeclaringType + " because Type.ContainsGenericParameters is true.");
  532. if ((invokeAttr & BindingFlags.CreateInstance) != 0 && DeclaringType.IsAbstract) {
  533. throw new MemberAccessException (String.Format ("Cannot create an instance of {0} because it is an abstract class", DeclaringType));
  534. }
  535. return InternalInvoke (obj, parameters);
  536. }
  537. public object InternalInvoke (object obj, object[] parameters)
  538. {
  539. Exception exc;
  540. object o = null;
  541. try {
  542. o = InternalInvoke (obj, parameters, out exc);
  543. #if NET_2_1
  544. } catch (MethodAccessException) {
  545. throw;
  546. #endif
  547. } catch (Exception e) {
  548. throw new TargetInvocationException (e);
  549. }
  550. if (exc != null)
  551. throw exc;
  552. return obj == null ? o : null;
  553. }
  554. [DebuggerHidden]
  555. [DebuggerStepThrough]
  556. public override Object Invoke (BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  557. {
  558. return DoInvoke (null, invokeAttr, binder, parameters, culture);
  559. }
  560. public override RuntimeMethodHandle MethodHandle {
  561. get {
  562. return new RuntimeMethodHandle (mhandle);
  563. }
  564. }
  565. public override MethodAttributes Attributes {
  566. get {
  567. return MonoMethodInfo.GetAttributes (mhandle);
  568. }
  569. }
  570. public override CallingConventions CallingConvention {
  571. get {
  572. return MonoMethodInfo.GetCallingConvention (mhandle);
  573. }
  574. }
  575. public override bool ContainsGenericParameters {
  576. get {
  577. return DeclaringType.ContainsGenericParameters;
  578. }
  579. }
  580. public override Type ReflectedType {
  581. get {
  582. return reftype;
  583. }
  584. }
  585. public override Type DeclaringType {
  586. get {
  587. return MonoMethodInfo.GetDeclaringType (mhandle);
  588. }
  589. }
  590. public override string Name {
  591. get {
  592. if (name != null)
  593. return name;
  594. return MonoMethod.get_name (this);
  595. }
  596. }
  597. public override bool IsDefined (Type attributeType, bool inherit) {
  598. return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
  599. }
  600. public override object[] GetCustomAttributes( bool inherit) {
  601. return MonoCustomAttrs.GetCustomAttributes (this, inherit);
  602. }
  603. public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
  604. return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
  605. }
  606. public override MethodBody GetMethodBody () {
  607. return GetMethodBody (mhandle);
  608. }
  609. public override string ToString () {
  610. StringBuilder sb = new StringBuilder ();
  611. sb.Append ("Void ");
  612. sb.Append (Name);
  613. sb.Append ("(");
  614. ParameterInfo[] p = GetParameters ();
  615. for (int i = 0; i < p.Length; ++i) {
  616. if (i > 0)
  617. sb.Append (", ");
  618. sb.Append (p[i].ParameterType.Name);
  619. }
  620. if (CallingConvention == CallingConventions.Any)
  621. sb.Append (", ...");
  622. sb.Append (")");
  623. return sb.ToString ();
  624. }
  625. public override IList<CustomAttributeData> GetCustomAttributesData () {
  626. return CustomAttributeData.GetCustomAttributes (this);
  627. }
  628. }
  629. }