MonoMethod.cs 22 KB

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