Merge pull request #2394 from Mailaender/patch-1
[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 MonoType))
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                 //seclevel { transparent = 0, safe-critical = 1, critical = 2}
506                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
507                 public extern int get_core_clr_security_level ();
508
509                 public override bool IsSecurityTransparent {
510                         get { return get_core_clr_security_level () == 0; }
511                 }
512
513                 public override bool IsSecurityCritical {
514                         get { return get_core_clr_security_level () > 0; }
515                 }
516
517                 public override bool IsSecuritySafeCritical {
518                         get { return get_core_clr_security_level () == 1; }
519                 }
520         }
521         
522
523         abstract class RuntimeConstructorInfo : ConstructorInfo, ISerializable
524         {
525                 public override Module Module {
526                         get {
527                                 return GetRuntimeModule ();
528                         }
529                 }
530
531                 internal RuntimeModule GetRuntimeModule ()
532                 {
533                         return RuntimeTypeHandle.GetModule((RuntimeType)DeclaringType);
534                 }
535
536                 internal BindingFlags BindingFlags {
537                         get {
538                                 return 0;
539                         }
540                 }
541
542                 RuntimeType ReflectedTypeInternal {
543                         get {
544                                 return (RuntimeType) ReflectedType;
545                         }
546                 }
547
548         #region ISerializable Implementation
549         public void GetObjectData(SerializationInfo info, StreamingContext context)
550         {
551             if (info == null)
552                 throw new ArgumentNullException("info");
553             Contract.EndContractBlock();
554             MemberInfoSerializationHolder.GetSerializationInfo(
555                 info,
556                 Name,
557                 ReflectedTypeInternal,
558                 ToString(),
559                 SerializationToString(),
560                 MemberTypes.Constructor,
561                 null);
562         }
563
564         internal string SerializationToString()
565         {
566             // We don't need the return type for constructors.
567             return FormatNameAndSig(true);
568         }
569
570                 internal void SerializationInvoke (Object target, SerializationInfo info, StreamingContext context)
571                 {
572                         Invoke (target, new object[] { info, context });
573                 }
574        #endregion
575         }
576
577         [Serializable()]
578         [StructLayout (LayoutKind.Sequential)]
579         internal class MonoCMethod : RuntimeConstructorInfo
580         {
581 #pragma warning disable 649             
582                 internal IntPtr mhandle;
583                 string name;
584                 Type reftype;
585 #pragma warning restore 649             
586                 
587                 public override MethodImplAttributes GetMethodImplementationFlags ()
588                 {
589                         return MonoMethodInfo.GetMethodImplementationFlags (mhandle);
590                 }
591
592                 public override ParameterInfo[] GetParameters ()
593                 {
594                         return MonoMethodInfo.GetParametersInfo (mhandle, this);
595                 }
596
597                 internal override ParameterInfo[] GetParametersInternal ()
598                 {
599                         return MonoMethodInfo.GetParametersInfo (mhandle, this);
600                 }               
601
602                 internal override int GetParametersCount ()
603                 {
604                         var pi = MonoMethodInfo.GetParametersInfo (mhandle, this);
605                         return pi == null ? 0 : pi.Length;
606                 }
607
608                 /*
609                  * InternalInvoke() receives the parameters correctly converted by the binder
610                  * to match the types of the method signature.
611                  */
612                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
613                 internal extern Object InternalInvoke (Object obj, Object[] parameters, out Exception exc);
614
615                 [DebuggerHidden]
616                 [DebuggerStepThrough]
617                 public override object Invoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) 
618                 {
619                         if (obj == null) {
620                                 if (!IsStatic)
621                                         throw new TargetException ("Instance constructor requires a target");
622                         } else if (!DeclaringType.IsInstanceOfType (obj)) {
623                                 throw new TargetException ("Constructor does not match target type");                           
624                         }
625
626                         return DoInvoke (obj, invokeAttr, binder, parameters, culture);
627                 }
628
629                 object DoInvoke (object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) 
630                 {
631                         if (binder == null)
632                                 binder = Type.DefaultBinder;
633
634                         ParameterInfo[] pinfo = MonoMethodInfo.GetParametersInfo (mhandle, this);
635
636                         MonoMethod.ConvertValues (binder, parameters, pinfo, culture, invokeAttr);
637
638                         if (obj == null && DeclaringType.ContainsGenericParameters)
639                                 throw new MemberAccessException ("Cannot create an instance of " + DeclaringType + " because Type.ContainsGenericParameters is true.");
640
641                         if ((invokeAttr & BindingFlags.CreateInstance) != 0 && DeclaringType.IsAbstract) {
642                                 throw new MemberAccessException (String.Format ("Cannot create an instance of {0} because it is an abstract class", DeclaringType));
643                         }
644
645                         return InternalInvoke (obj, parameters);
646                 }
647
648                 public object InternalInvoke (object obj, object[] parameters)
649                 {
650                         Exception exc;
651                         object o = null;
652
653                         try {
654                                 o = InternalInvoke (obj, parameters, out exc);
655 #if NET_2_1
656                         } catch (MethodAccessException) {
657                                 throw;
658 #endif
659                         } catch (Exception e) {
660                                 throw new TargetInvocationException (e);
661                         }
662
663                         if (exc != null)
664                                 throw exc;
665
666                         return obj == null ? o : null;
667                 }
668
669                 [DebuggerHidden]
670                 [DebuggerStepThrough]
671                 public override Object Invoke (BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
672                 {
673                         return DoInvoke (null, invokeAttr, binder, parameters, culture);
674                 }
675
676                 public override RuntimeMethodHandle MethodHandle { 
677                         get {
678                                 return new RuntimeMethodHandle (mhandle);
679                         } 
680                 }
681                 
682                 public override MethodAttributes Attributes { 
683                         get {
684                                 return MonoMethodInfo.GetAttributes (mhandle);
685                         } 
686                 }
687
688                 public override CallingConventions CallingConvention { 
689                         get {
690                                 return MonoMethodInfo.GetCallingConvention (mhandle);
691                         }
692                 }
693                 
694                 public override bool ContainsGenericParameters {
695                         get {
696                                 return DeclaringType.ContainsGenericParameters;
697                         }
698                 }
699
700                 public override Type ReflectedType {
701                         get {
702                                 return reftype;
703                         }
704                 }
705                 public override Type DeclaringType {
706                         get {
707                                 return MonoMethodInfo.GetDeclaringType (mhandle);
708                         }
709                 }
710                 public override string Name {
711                         get {
712                                 if (name != null)
713                                         return name;
714                                 return MonoMethod.get_name (this);
715                         }
716                 }
717
718                 public override bool IsDefined (Type attributeType, bool inherit) {
719                         return MonoCustomAttrs.IsDefined (this, attributeType, inherit);
720                 }
721
722                 public override object[] GetCustomAttributes( bool inherit) {
723                         return MonoCustomAttrs.GetCustomAttributes (this, inherit);
724                 }
725
726                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
727                         return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
728                 }
729
730                 public override MethodBody GetMethodBody () {
731                         return GetMethodBody (mhandle);
732                 }
733
734                 public override string ToString () {
735                         StringBuilder sb = new StringBuilder ();
736                         sb.Append ("Void ");
737                         sb.Append (Name);
738                         sb.Append ("(");
739                         ParameterInfo[] p = GetParameters ();
740                         for (int i = 0; i < p.Length; ++i) {
741                                 if (i > 0)
742                                         sb.Append (", ");
743                                 sb.Append (p[i].ParameterType.Name);
744                         }
745                         if (CallingConvention == CallingConventions.Any)
746                                 sb.Append (", ...");
747                         sb.Append (")");
748                         return sb.ToString ();
749                 }
750
751                 public override IList<CustomAttributeData> GetCustomAttributesData () {
752                         return CustomAttributeData.GetCustomAttributes (this);
753                 }
754         }
755 }