Merge pull request #3040 from xmcclure/debugger-step-recursive
[mono.git] / mcs / class / corlib / System.Reflection / MonoMethod.cs
1 //
2 // MonoMethod.cs: The class used to represent methods from the mono runtime.
3 //
4 // Authors:
5 //   Paolo Molaro (lupus@ximian.com)
6 //   Marek Safar (marek.safar@gmail.com)
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
32 using System.Collections.Generic;
33 using System.Globalization;
34 using System.Runtime.CompilerServices;
35 using System.Runtime.InteropServices;
36 using System.Runtime.Serialization;
37 #if !FULL_AOT_RUNTIME
38 using System.Reflection.Emit;
39 #endif
40 using System.Security;
41 using System.Threading;
42 using System.Text;
43 using System.Diagnostics;
44 using System.Diagnostics.Contracts;
45
46 namespace System.Reflection {
47         
48         internal struct MonoMethodInfo 
49         {
50 #pragma warning disable 649     
51                 private Type parent;
52                 private Type ret;
53                 internal MethodAttributes attrs;
54                 internal MethodImplAttributes iattrs;
55                 private CallingConventions callconv;
56 #pragma warning restore 649             
57
58                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
59                 static extern void get_method_info (IntPtr handle, out MonoMethodInfo info);
60                 
61                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
62                 static extern int get_method_attributes (IntPtr handle);
63                 
64                 internal static MonoMethodInfo GetMethodInfo (IntPtr handle)
65                 {
66                         MonoMethodInfo info;
67                         MonoMethodInfo.get_method_info (handle, out info);
68                         return info;
69                 }
70
71                 internal static Type GetDeclaringType (IntPtr handle)
72                 {
73                         return GetMethodInfo (handle).parent;
74                 }
75
76                 internal static Type GetReturnType (IntPtr handle)
77                 {
78                         return GetMethodInfo (handle).ret;
79                 }
80
81                 internal static MethodAttributes GetAttributes (IntPtr handle)
82                 {
83                         return (MethodAttributes)get_method_attributes (handle);
84                 }
85
86                 internal static CallingConventions GetCallingConvention (IntPtr handle)
87                 {
88                         return GetMethodInfo (handle).callconv;
89                 }
90
91                 internal static MethodImplAttributes GetMethodImplementationFlags (IntPtr handle)
92                 {
93                         return GetMethodInfo (handle).iattrs;
94                 }
95
96                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
97                 static extern ParameterInfo[] get_parameter_info (IntPtr handle, MemberInfo member);
98
99                 static internal ParameterInfo[] GetParametersInfo (IntPtr handle, MemberInfo member)
100                 {
101                         return get_parameter_info (handle, member);
102                 }
103
104                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
105                 static extern MarshalAsAttribute get_retval_marshal (IntPtr handle);
106
107                 static internal ParameterInfo GetReturnParameterInfo (MonoMethod method)
108                 {
109                         return ParameterInfo.New (GetReturnType (method.mhandle), method, get_retval_marshal (method.mhandle));
110                 }
111         };
112         
113         abstract class RuntimeMethodInfo : MethodInfo, ISerializable
114         {
115                 internal BindingFlags BindingFlags {
116                         get {
117                                 return 0;
118                         }
119                 }
120
121                 public override Module Module {
122                         get {
123                                 return GetRuntimeModule ();
124                         }
125                 }
126
127                 RuntimeType ReflectedTypeInternal {
128                         get {
129                                 return (RuntimeType) ReflectedType;
130                         }
131                 }
132
133         internal override string FormatNameAndSig (bool serialization)
134         {
135             // Serialization uses ToString to resolve MethodInfo overloads.
136             StringBuilder sbName = new StringBuilder(Name);
137
138             // serialization == true: use unambiguous (except for assembly name) type names to distinguish between overloads.
139             // serialization == false: use basic format to maintain backward compatibility of MethodInfo.ToString().
140             TypeNameFormatFlags format = serialization ? TypeNameFormatFlags.FormatSerialization : TypeNameFormatFlags.FormatBasic;
141
142             if (IsGenericMethod)
143                 sbName.Append(RuntimeMethodHandle.ConstructInstantiation(this, format));
144
145             sbName.Append("(");
146             ParameterInfo.FormatParameters (sbName, GetParametersNoCopy (), CallingConvention, serialization);
147             sbName.Append(")");
148
149             return sbName.ToString();
150         }
151
152                 public override Delegate CreateDelegate (Type delegateType)
153                 {
154                         return Delegate.CreateDelegate (delegateType, this);
155                 }
156
157                 public override Delegate CreateDelegate (Type delegateType, object target)
158                 {
159                         return Delegate.CreateDelegate (delegateType, target, this);
160                 }
161
162         public override String ToString() 
163         {
164             return ReturnType.FormatTypeName() + " " + FormatNameAndSig(false);
165         }
166
167                 internal RuntimeModule GetRuntimeModule ()
168                 {
169                         return ((RuntimeType)DeclaringType).GetRuntimeModule();
170                 }
171
172         #region ISerializable Implementation
173         public void GetObjectData(SerializationInfo info, StreamingContext context)
174         {
175             if (info == null)
176                 throw new ArgumentNullException("info");
177             Contract.EndContractBlock();
178
179             MemberInfoSerializationHolder.GetSerializationInfo(
180                 info,
181                 Name,
182                 ReflectedTypeInternal,
183                 ToString(),
184                 SerializationToString(),
185                 MemberTypes.Method,
186                 IsGenericMethod & !IsGenericMethodDefinition ? GetGenericArguments() : null);
187         }
188
189         internal string SerializationToString()
190         {
191             return ReturnType.FormatTypeName(true) + " " + FormatNameAndSig(true);
192         }
193         #endregion
194         }
195
196         /*
197          * Note: most of this class needs to be duplicated for the contructor, since
198          * the .NET reflection class hierarchy is so broken.
199          */
200         [Serializable()]
201         [StructLayout (LayoutKind.Sequential)]
202         internal class MonoMethod : RuntimeMethodInfo
203         {
204 #pragma warning disable 649
205                 internal IntPtr mhandle;
206                 string name;
207                 Type reftype;
208 #pragma warning restore 649
209
210                 internal MonoMethod () {
211                 }
212
213                 internal MonoMethod (RuntimeMethodHandle mhandle) {
214                         this.mhandle = mhandle.Value;
215                 }
216                 
217                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
218                 internal static extern string get_name (MethodBase method);
219
220                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
221                 internal static extern MonoMethod get_base_method (MonoMethod method, bool definition);
222
223                 public override MethodInfo GetBaseDefinition ()
224                 {
225                         return get_base_method (this, true);
226                 }
227
228                 internal override MethodInfo GetBaseMethod ()
229                 {
230                         return get_base_method (this, false);
231                 }
232
233                 public override ParameterInfo ReturnParameter {
234                         get {
235                                 return MonoMethodInfo.GetReturnParameterInfo (this);
236                         }
237                 }
238
239                 public override Type ReturnType {
240                         get {
241                                 return MonoMethodInfo.GetReturnType (mhandle);
242                         }
243                 }
244                 public override ICustomAttributeProvider ReturnTypeCustomAttributes { 
245                         get {
246                                 return MonoMethodInfo.GetReturnParameterInfo (this);
247                         }
248                 }
249                 
250                 public override MethodImplAttributes GetMethodImplementationFlags ()
251                 {
252                         return MonoMethodInfo.GetMethodImplementationFlags (mhandle);
253                 }
254
255                 public override ParameterInfo[] GetParameters ()
256                 {
257                         var src = MonoMethodInfo.GetParametersInfo (mhandle, this);
258                         if (src.Length == 0)
259                                 return src;
260
261                         // Have to clone because GetParametersInfo icall returns cached value
262                         var dest = new ParameterInfo [src.Length];
263                         Array.FastCopy (src, 0, dest, 0, src.Length);
264                         return dest;
265                 }
266
267                 internal override ParameterInfo[] GetParametersInternal ()
268                 {
269                         return MonoMethodInfo.GetParametersInfo (mhandle, this);
270                 }
271                 
272                 internal override int GetParametersCount ()
273                 {
274                         return MonoMethodInfo.GetParametersInfo (mhandle, this).Length;
275                 }
276
277                 /*
278                  * InternalInvoke() receives the parameters correctly converted by the 
279                  * binder to match the types of the method signature.
280                  */
281                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
282                 internal extern Object InternalInvoke (Object obj, Object[] parameters, out Exception exc);
283
284                 [DebuggerHidden]
285                 [DebuggerStepThrough]
286                 public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) 
287                 {
288                         if (binder == null)
289                                 binder = Type.DefaultBinder;
290
291                         /*Avoid allocating an array every time*/
292                         ParameterInfo[] pinfo = GetParametersInternal ();
293                         ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
294
295                         if (ContainsGenericParameters)
296                                 throw new InvalidOperationException ("Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true.");
297
298                         Exception exc;
299                         object o = null;
300
301                         try {
302                                 // The ex argument is used to distinguish exceptions thrown by the icall
303                                 // from the exceptions thrown by the called method (which need to be
304                                 // wrapped in TargetInvocationException).
305                                 o = InternalInvoke (obj, parameters, out exc);
306                         } catch (ThreadAbortException) {
307                                 throw;
308 #if NET_2_1
309                         } catch (MethodAccessException) {
310                                 throw;
311 #endif
312                         } catch (Exception e) {
313                                 throw new TargetInvocationException (e);
314                         }
315
316                         if (exc != null)
317                                 throw exc;
318                         return o;
319                 }
320
321                 internal static void ConvertValues (Binder binder, object[] args, ParameterInfo[] pinfo, CultureInfo culture, BindingFlags invokeAttr)
322                 {
323                         if (args == null) {
324                                 if (pinfo.Length == 0)
325                                         return;
326
327                                 throw new TargetParameterCountException ();
328                         }
329
330                         if (pinfo.Length != args.Length)
331                                 throw new TargetParameterCountException ();
332
333                         for (int i = 0; i < args.Length; ++i) {
334                                 var arg = args [i];
335                                 var pi = pinfo [i];
336                                 if (arg == Type.Missing) {
337                                         if (pi.DefaultValue == System.DBNull.Value)
338                                                 throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"),"parameters");
339
340                                         args [i] = pi.DefaultValue;
341                                         continue;
342                                 }
343
344                                 var rt = (RuntimeType) pi.ParameterType;
345                                 args [i] = rt.CheckValue (arg, binder, culture, invokeAttr);
346                         }
347                 }
348
349                 public override RuntimeMethodHandle MethodHandle { 
350                         get {
351                                 return new RuntimeMethodHandle (mhandle);
352                         } 
353                 }
354                 
355                 public override MethodAttributes Attributes { 
356                         get {
357                                 return MonoMethodInfo.GetAttributes (mhandle);
358                         } 
359                 }
360
361                 public override CallingConventions CallingConvention { 
362                         get {
363                                 return MonoMethodInfo.GetCallingConvention (mhandle);
364                         }
365                 }
366                 
367                 public override Type ReflectedType {
368                         get {
369                                 return reftype;
370                         }
371                 }
372                 public override Type DeclaringType {
373                         get {
374                                 return MonoMethodInfo.GetDeclaringType (mhandle);
375                         }
376                 }
377                 public override string Name {
378                         get {
379                                 if (name != null)
380                                         return name;
381                                 return get_name (this);
382                         }
383                 }
384                 
385                 public override bool IsDefined (Type attributeType, bool inherit) {
386                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
387                 }
388
389                 public override object[] GetCustomAttributes( bool inherit) {
390                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
391                 }
392                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
393                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
394                 }
395
396                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
397                 internal extern void GetPInvoke (out PInvokeAttributes flags, out string entryPoint, out string dllName);
398
399                 internal object[] GetPseudoCustomAttributes ()
400                 {
401                         int count = 0;
402
403                         /* MS.NET doesn't report MethodImplAttribute */
404
405                         MonoMethodInfo info = MonoMethodInfo.GetMethodInfo (mhandle);
406                         if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
407                                 count ++;
408                         if ((info.attrs & MethodAttributes.PinvokeImpl) != 0)
409                                 count ++;
410                         
411                         if (count == 0)
412                                 return null;
413                         object[] attrs = new object [count];
414                         count = 0;
415
416                         if ((info.iattrs & MethodImplAttributes.PreserveSig) != 0)
417                                 attrs [count ++] = new PreserveSigAttribute ();
418                         if ((info.attrs & MethodAttributes.PinvokeImpl) != 0) {
419                                 attrs [count ++] = DllImportAttribute.GetCustomAttribute (this);
420                         }
421
422                         return attrs;
423                 }
424
425                 public override MethodInfo MakeGenericMethod (Type [] methodInstantiation)
426                 {
427                         if (methodInstantiation == null)
428                                 throw new ArgumentNullException ("methodInstantiation");
429
430                         if (!IsGenericMethodDefinition)
431                                 throw new InvalidOperationException ("not a generic method definition");
432
433                         /*FIXME add GetGenericArgumentsLength() internal vcall to speed this up*/
434                         if (GetGenericArguments ().Length != methodInstantiation.Length)
435                                 throw new ArgumentException ("Incorrect length");
436
437                         bool hasUserType = false;
438                         foreach (Type type in methodInstantiation) {
439                                 if (type == null)
440                                         throw new ArgumentNullException ();
441                                 if (!(type is RuntimeType))
442                                         hasUserType = true;
443                         }
444
445                         if (hasUserType)
446 #if FULL_AOT_RUNTIME
447                                 throw new NotSupportedException ("User types are not supported under full aot");
448 #else
449                                 return new MethodOnTypeBuilderInst (this, methodInstantiation);
450 #endif
451
452                         MethodInfo ret = MakeGenericMethod_impl (methodInstantiation);
453                         if (ret == null)
454                                 throw new ArgumentException (String.Format ("The method has {0} generic parameter(s) but {1} generic argument(s) were provided.", GetGenericArguments ().Length, methodInstantiation.Length));
455                         return ret;
456                 }
457
458                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
459                 extern MethodInfo MakeGenericMethod_impl (Type [] types);
460
461                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
462                 public override extern Type [] GetGenericArguments ();
463
464                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
465                 extern MethodInfo GetGenericMethodDefinition_impl ();
466
467                 public override MethodInfo GetGenericMethodDefinition ()
468                 {
469                         MethodInfo res = GetGenericMethodDefinition_impl ();
470                         if (res == null)
471                                 throw new InvalidOperationException ();
472
473                         return res;
474                 }
475
476                 public override extern bool IsGenericMethodDefinition {
477                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
478                         get;
479                 }
480
481                 public override extern bool IsGenericMethod {
482                         [MethodImplAttribute(MethodImplOptions.InternalCall)]
483                         get;
484                 }
485
486                 public override bool ContainsGenericParameters {
487                         get {
488                                 if (IsGenericMethod) {
489                                         foreach (Type arg in GetGenericArguments ())
490                                                 if (arg.ContainsGenericParameters)
491                                                         return true;
492                                 }
493                                 return DeclaringType.ContainsGenericParameters;
494                         }
495                 }
496
497                 public override MethodBody GetMethodBody () {
498                         return GetMethodBody (mhandle);
499                 }
500
501                 public override IList<CustomAttributeData> GetCustomAttributesData () {
502                         return CustomAttributeData.GetCustomAttributes (this);
503                 }
504
505 #if MOBILE
506                 static int get_core_clr_security_level ()
507                 {
508                         return 1;
509                 }
510 #else
511                 //seclevel { transparent = 0, safe-critical = 1, critical = 2}
512                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
513                 public extern int get_core_clr_security_level ();
514 #endif
515
516                 public override bool IsSecurityTransparent {
517                         get { return get_core_clr_security_level () == 0; }
518                 }
519
520                 public override bool IsSecurityCritical {
521                         get { return get_core_clr_security_level () > 0; }
522                 }
523
524                 public override bool IsSecuritySafeCritical {
525                         get { return get_core_clr_security_level () == 1; }
526                 }
527         }
528         
529
530         abstract class RuntimeConstructorInfo : ConstructorInfo, ISerializable
531         {
532                 public override Module Module {
533                         get {
534                                 return GetRuntimeModule ();
535                         }
536                 }
537
538                 internal RuntimeModule GetRuntimeModule ()
539                 {
540                         return RuntimeTypeHandle.GetModule((RuntimeType)DeclaringType);
541                 }
542
543                 internal BindingFlags BindingFlags {
544                         get {
545                                 return 0;
546                         }
547                 }
548
549                 RuntimeType ReflectedTypeInternal {
550                         get {
551                                 return (RuntimeType) ReflectedType;
552                         }
553                 }
554
555         #region ISerializable Implementation
556         public void GetObjectData(SerializationInfo info, StreamingContext context)
557         {
558             if (info == null)
559                 throw new ArgumentNullException("info");
560             Contract.EndContractBlock();
561             MemberInfoSerializationHolder.GetSerializationInfo(
562                 info,
563                 Name,
564                 ReflectedTypeInternal,
565                 ToString(),
566                 SerializationToString(),
567                 MemberTypes.Constructor,
568                 null);
569         }
570
571         internal string SerializationToString()
572         {
573             // We don't need the return type for constructors.
574             return FormatNameAndSig(true);
575         }
576
577                 internal void SerializationInvoke (Object target, SerializationInfo info, StreamingContext context)
578                 {
579                         Invoke (target, new object[] { info, context });
580                 }
581        #endregion
582         }
583
584         [Serializable()]
585         [StructLayout (LayoutKind.Sequential)]
586         internal class MonoCMethod : RuntimeConstructorInfo
587         {
588 #pragma warning disable 649             
589                 internal IntPtr mhandle;
590                 string name;
591                 Type reftype;
592 #pragma warning restore 649             
593                 
594                 public override MethodImplAttributes GetMethodImplementationFlags ()
595                 {
596                         return MonoMethodInfo.GetMethodImplementationFlags (mhandle);
597                 }
598
599                 public override ParameterInfo[] GetParameters ()
600                 {
601                         return MonoMethodInfo.GetParametersInfo (mhandle, this);
602                 }
603
604                 internal override ParameterInfo[] GetParametersInternal ()
605                 {
606                         return MonoMethodInfo.GetParametersInfo (mhandle, this);
607                 }               
608
609                 internal override int GetParametersCount ()
610                 {
611                         var pi = MonoMethodInfo.GetParametersInfo (mhandle, this);
612                         return pi == null ? 0 : pi.Length;
613                 }
614
615                 /*
616                  * InternalInvoke() receives the parameters correctly converted by the binder
617                  * to match the types of the method signature.
618                  */
619                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
620                 internal extern Object InternalInvoke (Object obj, Object[] parameters, out Exception exc);
621
622                 [DebuggerHidden]
623                 [DebuggerStepThrough]
624                 public override object Invoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) 
625                 {
626                         if (obj == null) {
627                                 if (!IsStatic)
628                                         throw new TargetException ("Instance constructor requires a target");
629                         } else if (!DeclaringType.IsInstanceOfType (obj)) {
630                                 throw new TargetException ("Constructor does not match target type");                           
631                         }
632
633                         return DoInvoke (obj, invokeAttr, binder, parameters, culture);
634                 }
635
636                 object DoInvoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) 
637                 {
638                         if (binder == null)
639                                 binder = Type.DefaultBinder;
640
641                         ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo (mhandle, this);
642
643                         MonoMethod.ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
644
645                         if (obj == null && DeclaringType.ContainsGenericParameters)
646                                 throw new MemberAccessException ("Cannot create an instance of " + DeclaringType + " because Type.ContainsGenericParameters is true.");
647
648                         if ((invokeAttr & BindingFlags.CreateInstance) != 0 && DeclaringType.IsAbstract) {
649                                 throw new MemberAccessException (String.Format ("Cannot create an instance of {0} because it is an abstract class", DeclaringType));
650                         }
651
652                         return InternalInvoke (obj, parameters);
653                 }
654
655                 public object InternalInvoke (object obj, object[] parameters)
656                 {
657                         Exception exc;
658                         object o = null;
659
660                         try {
661                                 o = InternalInvoke (obj, parameters, out exc);
662 #if NET_2_1
663                         } catch (MethodAccessException) {
664                                 throw;
665 #endif
666                         } catch (Exception e) {
667                                 throw new TargetInvocationException (e);
668                         }
669
670                         if (exc != null)
671                                 throw exc;
672
673                         return obj == null ? o : null;
674                 }
675
676                 [DebuggerHidden]
677                 [DebuggerStepThrough]
678                 public override Object Invoke (BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
679                 {
680                         return DoInvoke (null, invokeAttr, binder, parameters, culture);
681                 }
682
683                 public override RuntimeMethodHandle MethodHandle { 
684                         get {
685                                 return new RuntimeMethodHandle (mhandle);
686                         } 
687                 }
688                 
689                 public override MethodAttributes Attributes { 
690                         get {
691                                 return MonoMethodInfo.GetAttributes (mhandle);
692                         } 
693                 }
694
695                 public override CallingConventions CallingConvention { 
696                         get {
697                                 return MonoMethodInfo.GetCallingConvention (mhandle);
698                         }
699                 }
700                 
701                 public override bool ContainsGenericParameters {
702                         get {
703                                 return DeclaringType.ContainsGenericParameters;
704                         }
705                 }
706
707                 public override Type ReflectedType {
708                         get {
709                                 return reftype;
710                         }
711                 }
712                 public override Type DeclaringType {
713                         get {
714                                 return MonoMethodInfo.GetDeclaringType (mhandle);
715                         }
716                 }
717                 public override string Name {
718                         get {
719                                 if (name != null)
720                                         return name;
721                                 return MonoMethod.get_name (this);
722                         }
723                 }
724
725                 public override bool IsDefined (Type attributeType, bool inherit) {
726                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
727                 }
728
729                 public override object[] GetCustomAttributes( bool inherit) {
730                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
731                 }
732
733                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
734                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
735                 }
736
737                 public override MethodBody GetMethodBody () {
738                         return GetMethodBody (mhandle);
739                 }
740
741                 public override string ToString () {
742                         StringBuilder sb = new StringBuilder ();
743                         sb.Append ("Void ");
744                         sb.Append (Name);
745                         sb.Append ("(");
746                         ParameterInfo[] p = GetParameters ();
747                         for (int i = 0; i < p.Length; ++i) {
748                                 if (i > 0)
749                                         sb.Append (", ");
750                                 sb.Append (p[i].ParameterType.Name);
751                         }
752                         if (CallingConvention == CallingConventions.Any)
753                                 sb.Append (", ...");
754                         sb.Append (")");
755                         return sb.ToString ();
756                 }
757
758                 public override IList<CustomAttributeData> GetCustomAttributesData () {
759                         return CustomAttributeData.GetCustomAttributes (this);
760                 }
761
762 #if MOBILE
763                 static int get_core_clr_security_level ()
764                 {
765                         return 1;
766                 }
767 #else
768                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
769                 public extern int get_core_clr_security_level ();
770 #endif
771
772                 public override bool IsSecurityTransparent {
773                         get { return get_core_clr_security_level () == 0; }
774                 }
775
776                 public override bool IsSecurityCritical {
777                         get { return get_core_clr_security_level () > 0; }
778                 }
779
780                 public override bool IsSecuritySafeCritical {
781                         get { return get_core_clr_security_level () == 1; }
782                 }
783         }
784 }