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