Sre cleanup9 (#3661)
[mono.git] / mcs / class / corlib / System.Reflection.Emit / ConstructorOnTypeBuilderInst.cs
1 //
2 // System.Reflection.Emit/ConstructorOnTypeBuilderInst.cs
3 //
4 // Author:
5 //   Zoltan Varga (vargaz@gmail.com)
6 //
7 //
8 // Copyright (C) 2008 Novell, Inc (http://www.novell.com)
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 // 
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 // 
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 #if !FULL_AOT_RUNTIME
31 using System;
32 using System.Globalization;
33 using System.Reflection;
34 using System.Runtime.InteropServices;
35
36 namespace System.Reflection.Emit
37 {
38         /*
39          * This class represents a ctor of an instantiation of a generic type builder.
40          */
41         [StructLayout (LayoutKind.Sequential)]
42         internal class ConstructorOnTypeBuilderInst : ConstructorInfo
43         {
44                 #region Keep in sync with object-internals.h
45                 internal MonoGenericClass instantiation;
46                 internal ConstructorInfo cb;
47                 #endregion
48
49                 public ConstructorOnTypeBuilderInst (MonoGenericClass instantiation, ConstructorInfo cb)
50                 {
51                         this.instantiation = instantiation;
52                         this.cb = cb;
53                 }
54
55                 //
56                 // MemberInfo members
57                 //
58                 
59                 public override Type DeclaringType {
60                         get {
61                                 return instantiation;
62                         }
63                 }
64
65                 public override string Name {
66                         get {
67                                 return cb.Name;
68                         }
69                 }
70
71                 public override Type ReflectedType {
72                         get {
73                                 return instantiation;
74                         }
75                 }
76
77                 public override Module Module {
78                         get {
79                                 return cb.Module;
80                         }
81                 }
82
83                 public override bool IsDefined (Type attributeType, bool inherit)
84                 {
85                         return cb.IsDefined (attributeType, inherit);
86                 }
87
88                 public override object [] GetCustomAttributes (bool inherit)
89                 {
90                         return cb.GetCustomAttributes (inherit);
91                 }
92
93                 public override object [] GetCustomAttributes (Type attributeType, bool inherit)
94                 {
95                         return cb.GetCustomAttributes (attributeType, inherit);
96                 }
97
98                 //
99                 // MethodBase members
100                 //
101
102                 public override MethodImplAttributes GetMethodImplementationFlags ()
103                 {
104                         return cb.GetMethodImplementationFlags ();
105                 }
106
107                 public override ParameterInfo[] GetParameters ()
108                 {
109                         /*FIXME, maybe the right thing to do when the type is creates is to retrieve from the inflated type*/
110                         if (!instantiation.IsCreated)
111                                 throw new NotSupportedException ();
112
113                         return GetParametersInternal ();
114                 }
115
116                 internal override ParameterInfo[] GetParametersInternal ()
117                 {
118                         ParameterInfo [] res;
119                         if (cb is ConstructorBuilder) {
120                                 ConstructorBuilder cbuilder = (ConstructorBuilder)cb;
121                                 res = new ParameterInfo [cbuilder.parameters.Length];
122                                 for (int i = 0; i < cbuilder.parameters.Length; i++) {
123                                         Type type = instantiation.InflateType (cbuilder.parameters [i]);
124                                         res [i] = ParameterInfo.New (cbuilder.pinfo == null ? null : cbuilder.pinfo [i], type, this, i + 1);
125                                 }
126                         } else {
127                                 ParameterInfo[] parms = cb.GetParameters ();
128                                 res = new ParameterInfo [parms.Length];
129                                 for (int i = 0; i < parms.Length; i++) {
130                                         Type type = instantiation.InflateType (parms [i].ParameterType);
131                                         res [i] = ParameterInfo.New (parms [i], type, this, i + 1);
132                                 }
133                         }
134                         return res;
135                 }
136
137                 internal override Type[] GetParameterTypes () {
138                         if (cb is ConstructorBuilder) {
139                                 return (cb as ConstructorBuilder).parameters;
140                         } else {
141                                 ParameterInfo[] parms = cb.GetParameters ();
142                                 var res = new Type [parms.Length];
143                                 for (int i = 0; i < parms.Length; i++) {
144                                         res [i] = parms [i].ParameterType;
145                                 }
146                                 return res;
147                         }
148                 }
149
150                 // Called from the runtime to return the corresponding finished ConstructorInfo object
151                 internal ConstructorInfo RuntimeResolve () {
152                         var type = instantiation.InternalResolve ();
153                         return type.GetConstructor (cb);
154                 }
155
156                 public override int MetadataToken {
157                         get {
158                                 return base.MetadataToken;
159                         }
160                 }
161
162                 internal override int GetParametersCount ()
163                 {
164                         return cb.GetParametersCount ();
165                 }
166
167                 public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
168                 {
169                         return cb.Invoke (obj, invokeAttr, binder, parameters,
170                                 culture);
171                 }
172
173                 public override RuntimeMethodHandle MethodHandle {
174                         get {
175                                 return cb.MethodHandle;
176                         }
177                 }
178
179                 public override MethodAttributes Attributes {
180                         get {
181                                 return cb.Attributes;
182                         }
183                 }
184
185                 public override CallingConventions CallingConvention {
186                         get {
187                                 return cb.CallingConvention;
188                         }
189                 }
190
191                 public override Type [] GetGenericArguments ()
192                 {
193                         return cb.GetGenericArguments ();
194                 }
195
196                 public override bool ContainsGenericParameters {
197                         get {
198                                 return false;
199                         }
200                 }
201
202                 public override bool IsGenericMethodDefinition {
203                         get {
204                                 return false;
205                         }
206                 }
207
208                 public override bool IsGenericMethod {
209                         get {
210                                 return false;
211                         }
212                 }
213
214                 //
215                 // MethodBase members
216                 //
217
218                 public override object Invoke (BindingFlags invokeAttr, Binder binder, object[] parameters,
219                                                                            CultureInfo culture)
220                 {
221                         throw new InvalidOperationException ();
222                 }
223         }
224 }
225
226 #endif