[sgen] Fix printf-like format warnings
[mono.git] / mcs / class / corlib / System.Reflection.Emit / MethodBuilder.cs
1 //
2 // System.Reflection.Emit/MethodBuilder.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 //
9
10 //
11 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 #if !FULL_AOT_RUNTIME
34 using System;
35 using System.Reflection;
36 using System.Reflection.Emit;
37 using System.Globalization;
38 using System.Security;
39 using System.Security.Permissions;
40 using System.Runtime.CompilerServices;
41 using System.Runtime.InteropServices;
42 using System.Diagnostics.SymbolStore;
43 using System.Collections.Generic;
44
45 namespace System.Reflection.Emit
46 {
47         [ComVisible (true)]
48         [ComDefaultInterface (typeof (_MethodBuilder))]
49         [ClassInterface (ClassInterfaceType.None)]
50         [StructLayout (LayoutKind.Sequential)]
51         public sealed class MethodBuilder : MethodInfo, _MethodBuilder
52         {
53 #pragma warning disable 169, 414
54                 private RuntimeMethodHandle mhandle;
55                 private Type rtype;
56                 internal Type[] parameters;
57                 private MethodAttributes attrs; /* It's used directly by MCS */
58                 private MethodImplAttributes iattrs;
59                 private string name;
60                 private int table_idx;
61                 private byte[] code;
62                 private ILGenerator ilgen;
63                 private TypeBuilder type;
64                 internal ParameterBuilder[] pinfo;
65                 private CustomAttributeBuilder[] cattrs;
66                 private MethodInfo[] override_methods;
67                 private string pi_dll;
68                 private string pi_entry;
69                 private CharSet charset;
70                 private uint extra_flags; /* this encodes set_last_error etc */
71                 private CallingConvention native_cc;
72                 private CallingConventions call_conv;
73                 private bool init_locals = true;
74                 private IntPtr generic_container;
75                 internal GenericTypeParameterBuilder[] generic_params;
76                 private Type[] returnModReq;
77                 private Type[] returnModOpt;
78                 private Type[][] paramModReq;
79                 private Type[][] paramModOpt;
80                 private RefEmitPermissionSet[] permissions;
81 #pragma warning restore 169, 414
82
83                 internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] returnModReq, Type[] returnModOpt, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt)
84                 {
85                         this.name = name;
86                         this.attrs = attributes;
87                         this.call_conv = callingConvention;
88                         this.rtype = returnType;
89                         this.returnModReq = returnModReq;
90                         this.returnModOpt = returnModOpt;
91                         this.paramModReq = paramModReq;
92                         this.paramModOpt = paramModOpt;
93                         // The MSDN docs does not specify this, but the MS MethodBuilder
94                         // appends a HasThis flag if the method is not static
95                         if ((attributes & MethodAttributes.Static) == 0)
96                                 this.call_conv |= CallingConventions.HasThis;
97                         if (parameterTypes != null) {
98                                 for (int i = 0; i < parameterTypes.Length; ++i)
99                                         if (parameterTypes [i] == null)
100                                                 throw new ArgumentException ("Elements of the parameterTypes array cannot be null", "parameterTypes");
101
102                                 this.parameters = new Type [parameterTypes.Length];
103                                 System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
104                         }
105                         type = tb;
106                         table_idx = get_next_table_index (this, 0x06, true);
107
108                         ((ModuleBuilder)tb.Module).RegisterToken (this, GetToken ().Token);
109                 }
110
111                 internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes, 
112                                                                 CallingConventions callingConvention, Type returnType, Type[] returnModReq, Type[] returnModOpt, Type[] parameterTypes, Type[][] paramModReq, Type[][] paramModOpt, 
113                         String dllName, String entryName, CallingConvention nativeCConv, CharSet nativeCharset) 
114                         : this (tb, name, attributes, callingConvention, returnType, returnModReq, returnModOpt, parameterTypes, paramModReq, paramModOpt)
115                 {
116                         pi_dll = dllName;
117                         pi_entry = entryName;
118                         native_cc = nativeCConv;
119                         charset = nativeCharset;
120                 }
121
122                 public override bool ContainsGenericParameters {
123                         get { throw new NotSupportedException (); }
124                 }
125
126                 public bool InitLocals {
127                         get {return init_locals;}
128                         set {init_locals = value;}
129                 }
130
131                 internal TypeBuilder TypeBuilder {
132                         get {return type;}
133                 }
134
135                 public override RuntimeMethodHandle MethodHandle {
136                         get {
137                                 throw NotSupported ();
138                         }
139                 }
140
141                 public override Type ReturnType {
142                         get { return rtype; }
143                 }
144
145                 public override Type ReflectedType {
146                         get { return type; }
147                 }
148
149                 public override Type DeclaringType {
150                         get { return type; }
151                 }
152
153                 public override string Name {
154                         get { return name; }
155                 }
156
157                 public override MethodAttributes Attributes {
158                         get { return attrs; }
159                 }
160
161                 public override ICustomAttributeProvider ReturnTypeCustomAttributes {
162                         get { return null; }
163                 }
164
165                 public override CallingConventions CallingConvention {
166                         get { return call_conv; }
167                 }
168
169                 [MonoTODO("Not implemented")]
170                 public string Signature {
171                         get {
172                                 throw new NotImplementedException ();
173                         }
174                 }
175
176                 /* Used by mcs */
177                 internal bool BestFitMapping {
178                         set {
179                                 extra_flags = (uint) ((extra_flags & ~0x30) | (uint)(value ? 0x10 : 0x20));
180                         }
181                 }
182
183                 /* Used by mcs */
184                 internal bool ThrowOnUnmappableChar {
185                         set {
186                                 extra_flags = (uint) ((extra_flags & ~0x3000) | (uint)(value ? 0x1000 : 0x2000));
187                         }
188                 }
189
190                 /* Used by mcs */
191                 internal bool ExactSpelling {
192                         set {
193                                 extra_flags = (uint) ((extra_flags & ~0x01) | (uint)(value ? 0x01 : 0x00));
194                         }
195                 }
196
197                 /* Used by mcs */
198                 internal bool SetLastError {
199                         set {
200                                 extra_flags = (uint) ((extra_flags & ~0x40) | (uint)(value ? 0x40 : 0x00));
201                         }
202                 }
203
204                 public MethodToken GetToken()
205                 {
206                         return new MethodToken(0x06000000 | table_idx);
207                 }
208                 
209                 public override MethodInfo GetBaseDefinition()
210                 {
211                         return this;
212                 }
213
214                 public override MethodImplAttributes GetMethodImplementationFlags()
215                 {
216                         return iattrs;
217                 }
218
219                 public override ParameterInfo[] GetParameters()
220                 {
221                         if (!type.is_created)
222                                 throw NotSupported ();
223
224                         return GetParametersInternal ();
225                 }
226
227                 internal override ParameterInfo[] GetParametersInternal ()
228                 {
229                         if (parameters == null)
230                                 return null;
231
232                         ParameterInfo[] retval = new ParameterInfo [parameters.Length];
233                         for (int i = 0; i < parameters.Length; i++) {
234                                 retval [i] = ParameterInfo.New (pinfo == null ? null : pinfo [i + 1], parameters [i], this, i + 1);
235                         }
236                         return retval;
237                 }
238                 
239                 internal override int GetParametersCount ()
240                 {
241                         if (parameters == null)
242                                 return 0;
243                         
244                         return parameters.Length;
245                 }
246
247                 internal override Type GetParameterType (int pos) {
248                         return parameters [pos];
249                 }
250
251                 public Module GetModule ()
252                 {
253                         return type.Module;
254                 }
255
256                 public void CreateMethodBody (byte[] il, int count)
257                 {
258                         if ((il != null) && ((count < 0) || (count > il.Length)))
259                                 throw new ArgumentOutOfRangeException ("Index was out of range.  Must be non-negative and less than the size of the collection.");
260
261                         if ((code != null) || type.is_created)
262                                 throw new InvalidOperationException ("Type definition of the method is complete.");
263
264                         if (il == null)
265                                 code = null;
266                         else {
267                                 code = new byte [count];
268                                 System.Array.Copy(il, code, count);
269                         }
270                 }
271
272                 public void SetMethodBody (byte[] il, int maxStack, byte[] localSignature,
273                         IEnumerable<ExceptionHandler> exceptionHandlers, IEnumerable<int> tokenFixups)
274                 {
275                         var ilgen = GetILGenerator ();
276                         ilgen.Init (il, maxStack, localSignature, exceptionHandlers, tokenFixups);
277                 }
278
279                 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
280                 {
281                         throw NotSupported ();
282                 }
283
284                 public override bool IsDefined (Type attributeType, bool inherit)
285                 {
286                         throw NotSupported ();
287                 }
288
289                 public override object[] GetCustomAttributes (bool inherit)
290                 {
291                         /*
292                          * On MS.NET, this always returns not_supported, but we can't do this
293                          * since there would be no way to obtain custom attributes of 
294                          * dynamically created ctors.
295                          */
296                         if (type.is_created)
297                                 return MonoCustomAttrs.GetCustomAttributes (this, inherit);
298                         else
299                                 throw NotSupported ();
300                 }
301
302                 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
303                 {
304                         if (type.is_created)
305                                 return MonoCustomAttrs.GetCustomAttributes (this, attributeType, inherit);
306                         else
307                                 throw NotSupported ();
308                 }
309
310                 public ILGenerator GetILGenerator ()
311                 {
312                         return GetILGenerator (64);
313                 }
314
315                 public ILGenerator GetILGenerator (int size)
316                 {
317                         if (((iattrs & MethodImplAttributes.CodeTypeMask) != 
318                                  MethodImplAttributes.IL) ||
319                                 ((iattrs & MethodImplAttributes.ManagedMask) != 
320                                  MethodImplAttributes.Managed))
321                                 throw new InvalidOperationException ("Method body should not exist.");
322                         if (ilgen != null)
323                                 return ilgen;
324                         ilgen = new ILGenerator (type.Module, ((ModuleBuilder)type.Module).GetTokenGenerator (), size);
325                         return ilgen;
326                 }
327                 
328                 public ParameterBuilder DefineParameter (int position, ParameterAttributes attributes, string strParamName)
329                 {
330                         RejectIfCreated ();
331                         
332                         //
333                         // Extension: Mono allows position == 0 for the return attribute
334                         //
335                         if ((position < 0) || (position > parameters.Length))
336                                 throw new ArgumentOutOfRangeException ("position");
337
338                         ParameterBuilder pb = new ParameterBuilder (this, position, attributes, strParamName);
339                         if (pinfo == null)
340                                 pinfo = new ParameterBuilder [parameters.Length + 1];
341                         pinfo [position] = pb;
342                         return pb;
343                 }
344
345                 internal void check_override ()
346                 {
347                         if (override_methods != null) {
348                                 foreach (var m in override_methods) {
349                                         if (m.IsVirtual && !IsVirtual)
350                                                 throw new TypeLoadException (String.Format("Method '{0}' override '{1}' but it is not virtual", name, m));
351                                 }
352                         }
353                 }
354
355                 internal void fixup ()
356                 {
357                         if (((attrs & (MethodAttributes.Abstract | MethodAttributes.PinvokeImpl)) == 0) && ((iattrs & (MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall)) == 0)) {
358                                 // do not allow zero length method body on MS.NET 2.0 (and higher)
359                                 if (((ilgen == null) || (ilgen.ILOffset == 0)) && (code == null || code.Length == 0))
360                                         throw new InvalidOperationException (
361                                                                              String.Format ("Method '{0}.{1}' does not have a method body.",
362                                                                                             DeclaringType.FullName, Name));
363                         }
364                         if (ilgen != null)
365                                 ilgen.label_fixup (this);
366                 }
367
368                 internal void ResolveUserTypes () {
369                         rtype = TypeBuilder.ResolveUserType (rtype);
370                         TypeBuilder.ResolveUserTypes (parameters);
371                         TypeBuilder.ResolveUserTypes (returnModReq);
372                         TypeBuilder.ResolveUserTypes (returnModOpt);
373                         if (paramModReq != null) {
374                                 foreach (var types in paramModReq)
375                                         TypeBuilder.ResolveUserTypes (types);
376                         }
377                         if (paramModOpt != null) {
378                                 foreach (var types in paramModOpt)
379                                         TypeBuilder.ResolveUserTypes (types);
380                         }
381                 }
382
383                 internal void GenerateDebugInfo (ISymbolWriter symbolWriter)
384                 {
385                         if (ilgen != null && ilgen.HasDebugInfo) {
386                                 SymbolToken token = new SymbolToken (GetToken().Token);
387                                 symbolWriter.OpenMethod (token);
388                                 symbolWriter.SetSymAttribute (token, "__name", System.Text.Encoding.UTF8.GetBytes (Name));
389                                 ilgen.GenerateDebugInfo (symbolWriter);
390                                 symbolWriter.CloseMethod ();
391                         }
392                 }
393
394                 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
395                 {
396                         if (customBuilder == null)
397                                 throw new ArgumentNullException ("customBuilder");
398
399                         switch (customBuilder.Ctor.ReflectedType.FullName) {
400                                 case "System.Runtime.CompilerServices.MethodImplAttribute":
401                                         byte[] data = customBuilder.Data;
402                                         int impla; // the (stupid) ctor takes a short or an int ... 
403                                         impla = (int)data [2];
404                                         impla |= ((int)data [3]) << 8;
405                                         iattrs |= (MethodImplAttributes)impla;
406                                         return;
407
408                                 case "System.Runtime.InteropServices.DllImportAttribute":
409                                         CustomAttributeBuilder.CustomAttributeInfo attr = CustomAttributeBuilder.decode_cattr (customBuilder);
410                                         bool preserveSig = true;
411
412                                         /*
413                                          * It would be easier to construct a DllImportAttribute from
414                                          * the custom attribute builder, but the DllImportAttribute 
415                                          * does not contain all the information required here, ie.
416                                          * - some parameters, like BestFitMapping has three values
417                                          *   ("on", "off", "missing"), but DllImportAttribute only
418                                          *   contains two (on/off).
419                                          * - PreserveSig is true by default, while it is false by
420                                          *   default in DllImportAttribute.
421                                          */
422
423                                         pi_dll = (string)attr.ctorArgs[0];
424                                         if (pi_dll == null || pi_dll.Length == 0)
425                                                 throw new ArgumentException ("DllName cannot be empty");
426
427                                         native_cc = System.Runtime.InteropServices.CallingConvention.Winapi;
428
429                                         for (int i = 0; i < attr.namedParamNames.Length; ++i) {
430                                                 string name = attr.namedParamNames [i];
431                                                 object value = attr.namedParamValues [i];
432
433                                                 if (name == "CallingConvention")
434                                                         native_cc = (CallingConvention)value;
435                                                 else if (name == "CharSet")
436                                                         charset = (CharSet)value;
437                                                 else if (name == "EntryPoint")
438                                                         pi_entry = (string)value;
439                                                 else if (name == "ExactSpelling")
440                                                         ExactSpelling = (bool)value;
441                                                 else if (name == "SetLastError")
442                                                         SetLastError = (bool)value;
443                                                 else if (name == "PreserveSig")
444                                                         preserveSig = (bool)value;
445                                         else if (name == "BestFitMapping")
446                                                 BestFitMapping = (bool)value;
447                                         else if (name == "ThrowOnUnmappableChar")
448                                                 ThrowOnUnmappableChar = (bool)value;
449                                         }
450
451                                         attrs |= MethodAttributes.PinvokeImpl;
452                                         if (preserveSig)
453                                                 iattrs |= MethodImplAttributes.PreserveSig;
454                                         return;
455
456                                 case "System.Runtime.InteropServices.PreserveSigAttribute":
457                                         iattrs |= MethodImplAttributes.PreserveSig;
458                                         return;
459                                 case "System.Runtime.CompilerServices.SpecialNameAttribute":
460                                         attrs |= MethodAttributes.SpecialName;
461                                         return;
462                                 case "System.Security.SuppressUnmanagedCodeSecurityAttribute":
463                                         attrs |= MethodAttributes.HasSecurity;
464                                         break;
465                         }
466
467                         if (cattrs != null) {
468                                 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
469                                 cattrs.CopyTo (new_array, 0);
470                                 new_array [cattrs.Length] = customBuilder;
471                                 cattrs = new_array;
472                         } else {
473                                 cattrs = new CustomAttributeBuilder [1];
474                                 cattrs [0] = customBuilder;
475                         }
476                 }
477
478                 [ComVisible (true)]
479                 public void SetCustomAttribute (ConstructorInfo con, byte[] binaryAttribute)
480                 {
481                         if (con == null)
482                                 throw new ArgumentNullException ("con");
483                         if (binaryAttribute == null)
484                                 throw new ArgumentNullException ("binaryAttribute");
485                         SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
486                 }
487
488                 public void SetImplementationFlags (MethodImplAttributes attributes)
489                 {
490                         RejectIfCreated ();
491                         iattrs = attributes;
492                 }
493
494                 public void AddDeclarativeSecurity (SecurityAction action, PermissionSet pset)
495                 {
496 #if !MOBILE
497                         if (pset == null)
498                                 throw new ArgumentNullException ("pset");
499                         if ((action == SecurityAction.RequestMinimum) ||
500                                 (action == SecurityAction.RequestOptional) ||
501                                 (action == SecurityAction.RequestRefuse))
502                                 throw new ArgumentOutOfRangeException ("Request* values are not permitted", "action");
503
504                         RejectIfCreated ();
505
506                         if (permissions != null) {
507                                 /* Check duplicate actions */
508                                 foreach (RefEmitPermissionSet set in permissions)
509                                         if (set.action == action)
510                                                 throw new InvalidOperationException ("Multiple permission sets specified with the same SecurityAction.");
511
512                                 RefEmitPermissionSet[] new_array = new RefEmitPermissionSet [permissions.Length + 1];
513                                 permissions.CopyTo (new_array, 0);
514                                 permissions = new_array;
515                         }
516                         else
517                                 permissions = new RefEmitPermissionSet [1];
518
519                         permissions [permissions.Length - 1] = new RefEmitPermissionSet (action, pset.ToXml ().ToString ());
520                         attrs |= MethodAttributes.HasSecurity;
521 #endif
522                 }
523
524                 [Obsolete ("An alternate API is available: Emit the MarshalAs custom attribute instead.")]
525                 public void SetMarshal (UnmanagedMarshal unmanagedMarshal)
526                 {
527                         RejectIfCreated ();
528                         throw new NotImplementedException ();
529                 }
530
531                 [MonoTODO]
532                 public void SetSymCustomAttribute (string name, byte[] data)
533                 {
534                         RejectIfCreated ();
535                         throw new NotImplementedException ();
536                 }
537
538                 public override string ToString()
539                 {
540                         return "MethodBuilder [" + type.Name + "::" + name + "]";
541                 }
542
543                 [MonoTODO]
544                 public override bool Equals (object obj)
545                 {
546                         return base.Equals (obj);
547                 }
548
549                 public override int GetHashCode ()
550                 {
551                         return name.GetHashCode ();
552                 }
553
554                 internal override int get_next_table_index (object obj, int table, bool inc)
555                 {
556                         return type.get_next_table_index (obj, table, inc);
557                 }
558
559                 void ExtendArray<T> (ref T[] array, T elem) {
560                         if (array == null) {
561                                 array = new T [1];
562                         } else {
563                                 var newa = new T [array.Length + 1];
564                                 Array.Copy (array, newa, array.Length);
565                                 array = newa;
566                         }
567                         array [array.Length - 1] = elem;
568                 }
569
570                 internal void set_override (MethodInfo mdecl)
571                 {
572                         ExtendArray<MethodInfo> (ref override_methods, mdecl);
573                 }
574
575                 private void RejectIfCreated ()
576                 {
577                         if (type.is_created)
578                                 throw new InvalidOperationException ("Type definition of the method is complete.");
579                 }
580
581                 private Exception NotSupported ()
582                 {
583                         return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
584                 }
585
586                 public override MethodInfo MakeGenericMethod (params Type [] typeArguments)
587                 {
588                         if (!IsGenericMethodDefinition)
589                                 throw new InvalidOperationException ("Method is not a generic method definition");
590                         if (typeArguments == null)
591                                 throw new ArgumentNullException ("typeArguments");
592                         if (generic_params.Length != typeArguments.Length)
593                                 throw new ArgumentException ("Incorrect length", "typeArguments");
594                         foreach (Type type in typeArguments) {
595                                 if (type == null)
596                                         throw new ArgumentNullException ("typeArguments");
597                         }
598
599                         return new MethodOnTypeBuilderInst (this, typeArguments);
600                 }
601
602                 public override bool IsGenericMethodDefinition {
603                         get {
604                                 return generic_params != null;
605                         }
606                 }
607
608                 public override bool IsGenericMethod {
609                         get {
610                                 return generic_params != null;
611                         }
612                 }
613
614                 public override MethodInfo GetGenericMethodDefinition ()
615                 {
616                         if (!IsGenericMethodDefinition)
617                                 throw new InvalidOperationException ();
618
619                         return this;
620                 }
621
622                 public override Type[] GetGenericArguments ()
623                 {
624                         if (generic_params == null)
625                                 return null;
626
627                         Type[] result = new Type [generic_params.Length];
628                         for (int i = 0; i < generic_params.Length; i++)
629                                 result [i] = generic_params [i];
630
631                         return result;
632                 }
633
634                 public GenericTypeParameterBuilder[] DefineGenericParameters (params string[] names)
635                 {
636                         if (names == null)
637                                 throw new ArgumentNullException ("names");
638                         if (names.Length == 0)
639                                 throw new ArgumentException ("names");
640
641                         generic_params = new GenericTypeParameterBuilder [names.Length];
642                         for (int i = 0; i < names.Length; i++) {
643                                 string item = names [i];
644                                 if (item == null)
645                                         throw new ArgumentNullException ("names");
646                                 generic_params [i] = new GenericTypeParameterBuilder (type, this, item, i);
647                         }
648
649                         return generic_params;
650                 }
651
652                 public void SetReturnType (Type returnType)
653                 {
654                         rtype = returnType;
655                 }
656
657                 public void SetParameters (params Type[] parameterTypes)
658                 {
659                         if (parameterTypes != null) {
660                                 for (int i = 0; i < parameterTypes.Length; ++i)
661                                         if (parameterTypes [i] == null)
662                                                 throw new ArgumentException ("Elements of the parameterTypes array cannot be null", "parameterTypes");
663
664                                 this.parameters = new Type [parameterTypes.Length];
665                                 System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
666                         }
667                 }
668
669                 public void SetSignature (Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers)
670                 {
671                         SetReturnType (returnType);
672                         SetParameters (parameterTypes);
673                         this.returnModReq = returnTypeRequiredCustomModifiers;
674                         this.returnModOpt = returnTypeOptionalCustomModifiers;
675                         this.paramModReq = parameterTypeRequiredCustomModifiers;
676                         this.paramModOpt = parameterTypeOptionalCustomModifiers;
677                 }
678
679                 public override Module Module {
680                         get {
681                                 return GetModule ();
682                         }
683                 }
684
685                 void _MethodBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
686                 {
687                         throw new NotImplementedException ();
688                 }
689
690                 void _MethodBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
691                 {
692                         throw new NotImplementedException ();
693                 }
694
695                 void _MethodBuilder.GetTypeInfoCount (out uint pcTInfo)
696                 {
697                         throw new NotImplementedException ();
698                 }
699
700                 void _MethodBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
701                 {
702                         throw new NotImplementedException ();
703                 }
704
705                 public override ParameterInfo ReturnParameter {
706                         get { return base.ReturnParameter; }
707                 }
708         }
709 }
710 #endif