bdfaaf5ec64079d483f64c9c8446afa294fefd59
[mono.git] / mcs / class / corlib / System.Reflection.Emit / MethodBuilder.cs
1
2 //
3 // System.Reflection.Emit/MethodBuilder.cs
4 //
5 // Author:
6 //   Paolo Molaro (lupus@ximian.com)
7 //
8 // (C) 2001 Ximian, Inc.  http://www.ximian.com
9 //
10
11 using System;
12 using System.Reflection;
13 using System.Reflection.Emit;
14 using System.Globalization;
15 using System.Runtime.CompilerServices;
16
17 namespace System.Reflection.Emit {
18         public sealed class MethodBuilder : MethodInfo {
19                 private RuntimeMethodHandle mhandle;
20                 private Type rtype;
21                 private Type[] parameters;
22                 private MethodAttributes attrs;
23                 private string name;
24                 private int table_idx;
25                 private byte[] code;
26                 private ILGenerator ilgen;
27                 internal TypeBuilder type;
28                 private ParameterBuilder[] pinfo;
29
30                 internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
31                         this.name = name;
32                         this.attrs = attributes;
33                         // call conv
34                         this.rtype = returnType;
35                         if (parameterTypes != null) {
36                                 this.parameters = new Type [parameterTypes.Length];
37                                 System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
38                         }
39                         type = tb;
40                         table_idx = tb.module.assemblyb.get_next_table_index (0x06, true);
41                 }
42                 
43                 public override Type ReturnType {get {return rtype;}}
44                 public override Type ReflectedType {get {return null;}}
45                 public override Type DeclaringType {get {return type;}}
46                 public override string Name {get {return name;}}
47                 public override RuntimeMethodHandle MethodHandle {get {return mhandle;}}
48                 public override MethodAttributes Attributes {get {return attrs;}}
49                 public override ICustomAttributeProvider ReturnTypeCustomAttributes {
50                         get {return null;}
51                 }
52                 public MethodToken GetToken() {
53                         return new MethodToken(0x06000000 | table_idx);
54                 }
55                 
56                 public override MethodInfo GetBaseDefinition() {
57                         return null;
58                 }
59                 public override MethodImplAttributes GetMethodImplementationFlags() {
60                         return (MethodImplAttributes)0;
61                 }
62                 public override ParameterInfo[] GetParameters() {
63                         return null;
64                 }
65                 
66                 /*
67                  * FIXME: this method signature needs to be expanded to handle also
68                  * a ILGenerator.
69                  */
70                 public void CreateMethodBody( byte[] il, int count) {
71                         code = new byte [count];
72                         System.Array.Copy(il, code, count);
73                 }
74                 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
75                         return null;
76                 }
77                 public override bool IsDefined (Type attribute_type, bool inherit) {
78                         return false;
79                 }
80                 public override object[] GetCustomAttributes( bool inherit) {
81                         return null;
82                 }
83                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
84                         return null;
85                 }
86                 public ILGenerator GetILGenerator () {
87                         return GetILGenerator (256);
88                 }
89                 public ILGenerator GetILGenerator (int size) {
90                         ilgen = new ILGenerator (this, size);
91                         return ilgen;
92                 }
93
94                 public ParameterBuilder DefineParameter( int position, ParameterAttributes attributes, string strParamName) {
95                         ParameterBuilder pb = new ParameterBuilder (this, position, attributes, strParamName);
96                         /* FIXME: add it to pinfo */
97                         return pb;
98                 }
99
100                 internal void fixup () {
101                         if (ilgen != null)
102                                 ilgen.label_fixup ();
103                 }
104         }
105 }
106