Wed Feb 20 22:30:49 CET 2002 Paolo Molaro <lupus@ximian.com>
[mono.git] / mcs / class / corlib / System.Reflection.Emit / ConstructorBuilder.cs
1 //
2 // System.Reflection.Emit/ConstructorBuilder.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //
7 // (C) 2001 Ximian, Inc.  http://www.ximian.com
8 //
9
10 using System;
11 using System.Reflection;
12 using System.Reflection.Emit;
13 using System.Globalization;
14 using System.Security;
15 using System.Security.Permissions;
16
17 namespace System.Reflection.Emit {
18         public sealed class ConstructorBuilder : ConstructorInfo {
19                 private ILGenerator ilgen;
20                 private Type[] parameters;
21                 private MethodAttributes attrs;
22                 private MethodImplAttributes iattrs;
23                 private int table_idx;
24                 private CallingConventions call_conv;
25                 private TypeBuilder type;
26                 private ParameterBuilder[] pinfo;
27                 private CustomAttributeBuilder[] cattrs;
28
29                 internal ConstructorBuilder (TypeBuilder tb, MethodAttributes attributes, CallingConventions callingConvention, Type[] parameterTypes) {
30                         attrs = attributes;
31                         call_conv = callingConvention;
32                         if (parameterTypes != null) {
33                                 this.parameters = new Type [parameterTypes.Length];
34                                 System.Array.Copy (parameterTypes, this.parameters, parameterTypes.Length);
35                         }
36                         type = tb;
37                         table_idx = get_next_table_index (0x06, true);
38                 }
39                 
40                 internal TypeBuilder TypeBuilder {
41                         get {return type;}
42                 }
43                 
44                 public override MethodImplAttributes GetMethodImplementationFlags() {
45                         return iattrs;
46                 }
47                 public override ParameterInfo[] GetParameters() {
48                         return null;
49                 }
50                 public override Object Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) {
51                         return null;
52                 }
53                 public override object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture) {
54                         return null;
55                 }
56
57                 public override RuntimeMethodHandle MethodHandle { get {return new RuntimeMethodHandle ();} }
58                 public override MethodAttributes Attributes { 
59                         get {return attrs;} 
60                 }
61                 public override Type ReflectedType { get {return type;}}
62                 public override Type DeclaringType { get {return type;}}
63                 public Type ReturnType { get {return null;}}
64                 public override string Name { 
65                         get {return (attrs & MethodAttributes.Static) != 0 ? ".cctor" : ".ctor";}
66                 }
67                 public string Signature {
68                         get {return "constructor signature";}
69                 }
70
71                 [MonoTODO]
72                 public bool InitLocals { /* FIXME */
73                         get {return false;} 
74                         set {return;}
75                 }
76
77                 public void AddDeclarativeSecurity( SecurityAction action, PermissionSet pset) {
78                 }
79
80                 [MonoTODO]
81                 public ParameterBuilder DefineParameter(int iSequence, ParameterAttributes attributes, string strParamName)
82                 {
83                         ParameterBuilder pb = new ParameterBuilder (this, iSequence, attributes, strParamName);
84                         // check iSequence
85                         if (pinfo == null)
86                                 pinfo = new ParameterBuilder [parameters.Length + 1];
87                         pinfo [iSequence] = pb;
88                         return pb;
89                 }
90
91                 public override bool IsDefined (Type attribute_type, bool inherit) {return false;}
92
93                 public override object [] GetCustomAttributes (bool inherit) {return null;}
94
95                 public override object [] GetCustomAttributes (Type attribute_type, bool inherit) {return null;}
96
97                 public ILGenerator GetILGenerator () {
98                         return GetILGenerator (256);
99                 }
100                 public ILGenerator GetILGenerator (int size) {
101                         ilgen = new ILGenerator (this, size);
102                         return ilgen;
103                 }
104
105                 public void SetCustomAttribute( CustomAttributeBuilder customBuilder) {
106                         if (cattrs != null) {
107                                 CustomAttributeBuilder[] new_array = new CustomAttributeBuilder [cattrs.Length + 1];
108                                 cattrs.CopyTo (new_array, 0);
109                                 new_array [cattrs.Length] = customBuilder;
110                                 cattrs = new_array;
111                         } else {
112                                 cattrs = new CustomAttributeBuilder [1];
113                                 cattrs [0] = customBuilder;
114                         }
115                 }
116                 public void SetCustomAttribute( ConstructorInfo con, byte[] binaryAttribute) {
117                         SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
118                 }
119                 public void SetImplementationFlags( MethodImplAttributes attributes) {
120                         iattrs = attributes;
121                 }
122                 public Module GetModule() {
123                         return null;
124                 }
125                 public MethodToken GetToken() {
126                         return new MethodToken (0x06000000 | table_idx);
127                 }
128                 public void SetSymCustomAttribute( string name, byte[] data) {
129                 }
130                 public override string ToString() {
131                         return "constructor";
132                 }
133
134                 internal void fixup () {
135                         if (ilgen != null)
136                                 ilgen.label_fixup ();
137                 }
138                 internal override int get_next_table_index (int table, bool inc) {
139                         return type.get_next_table_index (table, inc);
140                 }
141
142         }
143 }