Merge pull request #1588 from BrzVlad/feature-aot-wbarrier
[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                 MonoGenericClass instantiation;
46                 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                 public override int MetadataToken {
138                         get {
139                                 return base.MetadataToken;
140                         }
141                 }
142
143                 internal override int GetParametersCount ()
144                 {
145                         return cb.GetParametersCount ();
146                 }
147
148                 public override Object Invoke (Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
149                 {
150                         return cb.Invoke (obj, invokeAttr, binder, parameters,
151                                 culture);
152                 }
153
154                 public override RuntimeMethodHandle MethodHandle {
155                         get {
156                                 return cb.MethodHandle;
157                         }
158                 }
159
160                 public override MethodAttributes Attributes {
161                         get {
162                                 return cb.Attributes;
163                         }
164                 }
165
166                 public override CallingConventions CallingConvention {
167                         get {
168                                 return cb.CallingConvention;
169                         }
170                 }
171
172                 public override Type [] GetGenericArguments ()
173                 {
174                         return cb.GetGenericArguments ();
175                 }
176
177                 public override bool ContainsGenericParameters {
178                         get {
179                                 return false;
180                         }
181                 }
182
183                 public override bool IsGenericMethodDefinition {
184                         get {
185                                 return false;
186                         }
187                 }
188
189                 public override bool IsGenericMethod {
190                         get {
191                                 return false;
192                         }
193                 }
194
195                 //
196                 // MethodBase members
197                 //
198
199                 public override object Invoke (BindingFlags invokeAttr, Binder binder, object[] parameters,
200                                                                            CultureInfo culture)
201                 {
202                         throw new InvalidOperationException ();
203                 }
204         }
205 }
206
207 #endif