Add license and copyright to all source files in corlib
[mono.git] / mcs / class / corlib / System.Reflection.Emit / GenericTypeParameterBuilder.cs
1 //
2 // System.Reflection.Emit.GenericTypeParameterBuilder
3 //
4 // Martin Baulig (martin@ximian.com)
5 //
6 // (C) 2004 Novell, Inc.
7 //
8
9 //
10 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 using System.Reflection;
33 using System.Reflection.Emit;
34 using System.Collections;
35 using System.Runtime.CompilerServices;
36 using System.Globalization;
37 using System.Runtime.Serialization;
38
39 #if NET_2_0 || BOOTSTRAP_NET_2_0
40 namespace System.Reflection.Emit
41 {
42         public sealed class GenericTypeParameterBuilder : Type
43         {
44         #region Sync with reflection.h
45                 private TypeBuilder tbuilder;
46                 private MethodBuilder mbuilder;
47                 private string name;
48                 private int index;
49                 private Type base_type;
50                 private Type[] iface_constraints;
51                 private bool has_ctor_constraint;
52                 private bool has_reference_type;
53                 private bool has_value_type;
54         #endregion
55
56                 public void SetBaseTypeConstraint (Type base_type_constraint)
57                 {
58                         this.base_type = base_type_constraint;
59                 }
60
61                 public void SetInterfaceConstraints (Type[] iface_constraints)
62                 {
63                         this.iface_constraints = iface_constraints;
64                 }
65
66                 public void Mono_SetConstructorConstraint ()
67                 {
68                         has_ctor_constraint = true;
69                 }
70
71                 public void Mono_SetReferenceTypeConstraint ()
72                 {
73                         has_reference_type = true;
74                 }
75
76                 public void Mono_SetValueTypeConstraint ()
77                 {
78                         has_value_type = true;
79                 }
80
81                 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
82                                                       MethodBuilder mbuilder,
83                                                       string name, int index)
84                 {
85                         this.tbuilder = tbuilder;
86                         this.mbuilder = mbuilder;
87                         this.name = name;
88                         this.index = index;
89
90                         initialize ();
91                 }
92
93                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
94                 private extern void initialize ();
95
96                 public override bool IsSubclassOf (Type c)
97                 {
98                         if (BaseType == null)
99                                 return false;
100                         else
101                                 return BaseType == c || BaseType.IsSubclassOf (c);
102                 }
103
104                 protected override TypeAttributes GetAttributeFlagsImpl ()
105                 {
106                         return TypeAttributes.Public;
107                 }
108
109                 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
110                                                                        Binder binder,
111                                                                        CallingConventions callConvention,
112                                                                        Type[] types,
113                                                                        ParameterModifier[] modifiers)
114                 {
115                         throw not_supported ();
116                 }
117
118                 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
119                 {
120                         throw not_supported ();
121                 }
122
123                 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
124                 {
125                         throw not_supported ();
126                 }
127
128                 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
129                 {
130                         throw not_supported ();
131                 }
132
133                 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
134                 {
135                         throw not_supported ();
136                 }
137
138                 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
139                 {
140                         throw not_supported ();
141                 }
142                 
143                 public override Type GetInterface (string name, bool ignoreCase)
144                 {
145                         throw not_supported ();
146                 }
147
148                 public override Type[] GetInterfaces ()
149                 {
150                         throw not_supported ();
151                 }
152                 
153                 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
154                 {
155                         throw not_supported ();
156                 }
157
158                 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
159                 {
160                         throw not_supported ();
161                 }
162
163                 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
164                                                              Binder binder,
165                                                              CallingConventions callConvention,
166                                                              Type[] types, ParameterModifier[] modifiers)
167                 {
168                         throw not_supported ();
169                 }
170
171                 public override Type GetNestedType (string name, BindingFlags bindingAttr)
172                 {
173                         throw not_supported ();
174                 }
175
176                 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
177                 {
178                         throw not_supported ();
179                 }
180
181                 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
182                 {
183                         throw not_supported ();
184                 }
185
186                 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
187                                                                  Binder binder, Type returnType,
188                                                                  Type[] types,
189                                                                  ParameterModifier[] modifiers)
190                 {
191                         throw not_supported ();
192                 }
193
194                 protected override bool HasElementTypeImpl ()
195                 {
196                         return false;
197                 }
198
199                 protected override bool IsArrayImpl ()
200                 {
201                         return false;
202                 }
203
204                 protected override bool IsByRefImpl ()
205                 {
206                         return false;
207                 }
208
209                 protected override bool IsCOMObjectImpl ()
210                 {
211                         return false;
212                 }
213
214                 protected override bool IsPointerImpl ()
215                 {
216                         return false;
217                 }
218
219                 protected override bool IsPrimitiveImpl ()
220                 {
221                         return false;
222                 }
223
224                 protected override bool IsValueTypeImpl ()
225                 {
226 #warning "FIXME"
227                         return false;
228                         // return base_type != null ? base_type.IsValueType : false;
229                 }
230                 
231                 public override object InvokeMember (string name, BindingFlags invokeAttr,
232                                                      Binder binder, object target, object[] args,
233                                                      ParameterModifier[] modifiers,
234                                                      CultureInfo culture, string[] namedParameters)
235                 {
236                         throw not_supported ();
237                 }
238
239                 public override Type GetElementType ()
240                 {
241                         throw not_supported ();
242                 }
243
244                 public override Type UnderlyingSystemType {
245                         get {
246                                 return null;
247                         }
248                 }
249
250                 public override Assembly Assembly {
251                         get { return tbuilder.Assembly; }
252                 }
253
254                 public override string AssemblyQualifiedName {
255                         get { return null; }
256                 }
257
258                 public override Type BaseType {
259                         get { return base_type; }
260                 }
261
262                 public override string FullName {
263                         get { return null; }
264                 }
265
266                 public override Guid GUID {
267                         get { return Guid.Empty; }
268                 }
269
270                 public override bool IsDefined (Type attributeType, bool inherit)
271                 {
272                         throw not_supported ();
273                 }
274
275                 public override object[] GetCustomAttributes (bool inherit)
276                 {
277                         throw not_supported ();
278                 }
279
280                 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
281                 {
282                         throw not_supported ();
283                 }
284
285                 public override MemberTypes MemberType {
286                         get { return MemberTypes.TypeInfo; }
287                 }
288
289                 public override string Name {
290                         get { return name; }
291                 }
292
293                 public override string Namespace {
294                         get { return null; }
295                 }
296
297                 public override Module Module {
298                         get { return tbuilder.Module; }
299                 }
300
301                 public override Type DeclaringType {
302                         get { return mbuilder != null ? null : tbuilder; }
303                 }
304
305                 public override Type ReflectedType {
306                         get {
307                                 return DeclaringType;
308                         }
309                 }
310
311                 public override RuntimeTypeHandle TypeHandle {
312                         get { throw not_supported (); }
313                 }
314
315                 public override int GetArrayRank ()
316                 {
317                         throw not_supported ();
318                 }
319
320                 public override Type[] GetGenericArguments ()
321                 {
322                         throw not_supported ();
323                 }
324
325                 public override Type GetGenericTypeDefinition ()
326                 {
327                         throw not_supported ();
328                 }
329
330                 public override bool HasGenericArguments {
331                         get { return false; }
332                 }
333
334                 public override bool ContainsGenericParameters {
335                         get { return false; }
336                 }
337
338                 public override bool IsGenericParameter {
339                         get { return true; }
340                 }
341
342                 public override int GenericParameterPosition {
343                         get { return index; }
344                 }
345
346                 public override MethodInfo DeclaringMethod {
347                         get { return mbuilder; }
348                 }
349
350                 private Exception not_supported ()
351                 {
352                         return new NotSupportedException ();
353                 }
354
355                 public override string ToString ()
356                 {
357                         return name;
358                 }
359         }
360 }
361 #endif