2325f0a8133527406c623edcc1848a1761be429b
[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 using System.Runtime.InteropServices;
17
18 namespace System.Reflection.Emit {
19         public sealed class MethodBuilder : MethodInfo {
20                 private RuntimeMethodHandle mhandle;
21                 private Type rtype;
22                 private Type[] parameters;
23                 private MethodAttributes attrs;
24                 private MethodImplAttributes iattrs;
25                 private string name;
26                 private int table_idx;
27                 private byte[] code;
28                 private ILGenerator ilgen;
29                 private TypeBuilder type;
30                 private ParameterBuilder[] pinfo;
31                 private MethodInfo override_method;
32                 private string pi_dll;
33                 private string pi_entry;
34                 private CharSet ncharset;
35                 private CallingConvention native_cc;
36                 private CallingConventions call_conv;
37
38                 internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] parameterTypes) {
39                         this.name = name;
40                         this.attrs = attributes;
41                         this.call_conv = callingConvention;
42                         this.rtype = returnType;
43                         if (parameterTypes != null) {
44                                 this.parameters = new Type [parameterTypes.Length];
45                                 System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
46                         }
47                         type = tb;
48                         table_idx = get_next_table_index (0x06, true);
49                         //Console.WriteLine ("index for "+name+" set to "+table_idx.ToString());
50                 }
51
52                 internal MethodBuilder (TypeBuilder tb, string name, MethodAttributes attributes, 
53                         CallingConventions callingConvention, Type returnType, Type[] parameterTypes, 
54                         String dllName, String entryName, CallingConvention nativeCConv, CharSet nativeCharset) 
55                         : this (tb, name, attributes, callingConvention, returnType, parameterTypes) {
56                         pi_dll = dllName;
57                         pi_entry = entryName;
58                         native_cc = nativeCConv;
59                         ncharset = nativeCharset;
60                 }
61
62                 internal TypeBuilder TypeBuilder {
63                         get {return type;}
64                 }
65                 
66                 public override Type ReturnType {get {return rtype;}}
67                 public override Type ReflectedType {get {return type;}}
68                 public override Type DeclaringType {get {return type;}}
69                 public override string Name {get {return name;}}
70                 public override RuntimeMethodHandle MethodHandle {get {return mhandle;}}
71                 public override MethodAttributes Attributes {get {return attrs;}}
72                 public override ICustomAttributeProvider ReturnTypeCustomAttributes {
73                         get {return null;}
74                 }
75                 public MethodToken GetToken() {
76                         return new MethodToken(0x06000000 | table_idx);
77                 }
78                 
79                 public override MethodInfo GetBaseDefinition() {
80                         return null;
81                 }
82                 public override MethodImplAttributes GetMethodImplementationFlags() {
83                         return iattrs;
84                 }
85                 public override ParameterInfo[] GetParameters() {
86                         return null;
87                 }
88                 
89                 public void CreateMethodBody( byte[] il, int count) {
90                         code = new byte [count];
91                         System.Array.Copy(il, code, count);
92                 }
93                 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
94                         return null;
95                 }
96                 public override bool IsDefined (Type attribute_type, bool inherit) {
97                         return false;
98                 }
99                 public override object[] GetCustomAttributes( bool inherit) {
100                         return null;
101                 }
102                 public override object[] GetCustomAttributes( Type attributeType, bool inherit) {
103                         return null;
104                 }
105                 public ILGenerator GetILGenerator () {
106                         return GetILGenerator (256);
107                 }
108                 public ILGenerator GetILGenerator (int size) {
109                         ilgen = new ILGenerator (this, size);
110                         return ilgen;
111                 }
112                 
113                 [MonoTODO]
114                 public ParameterBuilder DefineParameter (int position, ParameterAttributes attributes, string strParamName)
115                 {
116                         ParameterBuilder pb = new ParameterBuilder (this, position, attributes, strParamName);
117                         /* FIXME: add it to pinfo */
118                         return pb;
119                 }
120
121                 internal void fixup () {
122                         if (ilgen != null)
123                                 ilgen.label_fixup ();
124                 }
125
126                 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
127                 }
128                 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
129                 }
130                 public void SetImplementationFlags( MethodImplAttributes attributes) {
131                         iattrs = attributes;
132                 }
133                 internal override int get_next_table_index (int table, bool inc) {
134                         return type.get_next_table_index (table, inc);
135                 }
136
137                 internal void set_override (MethodInfo mdecl) {
138                         override_method = mdecl;
139                 }
140         }
141 }
142