Reflect latest generics API changes in the August CTP.
[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.Runtime.InteropServices;
37 using System.Globalization;
38 using System.Runtime.Serialization;
39
40 #if NET_2_0 || BOOTSTRAP_NET_2_0
41 namespace System.Reflection.Emit
42 {
43         [ComVisible (true)]
44         public sealed class GenericTypeParameterBuilder : Type
45         {
46         #region Sync with reflection.h
47                 private TypeBuilder tbuilder;
48                 private MethodBuilder mbuilder;
49                 private string name;
50                 private int index;
51                 private Type base_type;
52                 private Type[] iface_constraints;
53                 private GenericParameterAttributes attrs;
54         #endregion
55
56                 public void SetBaseTypeConstraint (Type base_type_constraint)
57                 {
58                         this.base_type = base_type_constraint;
59                 }
60
61                 [ComVisible (true)]
62                 public void SetInterfaceConstraints (Type[] iface_constraints)
63                 {
64                         this.iface_constraints = iface_constraints;
65                 }
66
67                 public void SetGenericParameterAttributes (GenericParameterAttributes attrs)
68                 {
69                         this.attrs = attrs;
70                 }
71
72                 internal GenericTypeParameterBuilder (TypeBuilder tbuilder,
73                                                       MethodBuilder mbuilder,
74                                                       string name, int index)
75                 {
76                         this.tbuilder = tbuilder;
77                         this.mbuilder = mbuilder;
78                         this.name = name;
79                         this.index = index;
80
81                         initialize ();
82                 }
83
84                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
85                 private extern void initialize ();
86
87                 public override bool IsSubclassOf (Type c)
88                 {
89                         if (BaseType == null)
90                                 return false;
91                         else
92                                 return BaseType == c || BaseType.IsSubclassOf (c);
93                 }
94
95                 protected override TypeAttributes GetAttributeFlagsImpl ()
96                 {
97                         return TypeAttributes.Public;
98                 }
99
100                 protected override ConstructorInfo GetConstructorImpl (BindingFlags bindingAttr,
101                                                                        Binder binder,
102                                                                        CallingConventions callConvention,
103                                                                        Type[] types,
104                                                                        ParameterModifier[] modifiers)
105                 {
106                         throw not_supported ();
107                 }
108
109                 public override ConstructorInfo[] GetConstructors (BindingFlags bindingAttr)
110                 {
111                         throw not_supported ();
112                 }
113
114                 public override EventInfo GetEvent (string name, BindingFlags bindingAttr)
115                 {
116                         throw not_supported ();
117                 }
118
119                 public override EventInfo[] GetEvents (BindingFlags bindingAttr)
120                 {
121                         throw not_supported ();
122                 }
123
124                 public override FieldInfo GetField (string name, BindingFlags bindingAttr)
125                 {
126                         throw not_supported ();
127                 }
128
129                 public override FieldInfo[] GetFields (BindingFlags bindingAttr)
130                 {
131                         throw not_supported ();
132                 }
133                 
134                 public override Type GetInterface (string name, bool ignoreCase)
135                 {
136                         throw not_supported ();
137                 }
138
139                 public override Type[] GetInterfaces ()
140                 {
141                         throw not_supported ();
142                 }
143                 
144                 public override MemberInfo[] GetMembers (BindingFlags bindingAttr)
145                 {
146                         throw not_supported ();
147                 }
148
149                 public override MethodInfo [] GetMethods (BindingFlags bindingAttr)
150                 {
151                         throw not_supported ();
152                 }
153
154                 protected override MethodInfo GetMethodImpl (string name, BindingFlags bindingAttr,
155                                                              Binder binder,
156                                                              CallingConventions callConvention,
157                                                              Type[] types, ParameterModifier[] modifiers)
158                 {
159                         throw not_supported ();
160                 }
161
162                 public override Type GetNestedType (string name, BindingFlags bindingAttr)
163                 {
164                         throw not_supported ();
165                 }
166
167                 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
168                 {
169                         throw not_supported ();
170                 }
171
172                 public override PropertyInfo [] GetProperties (BindingFlags bindingAttr)
173                 {
174                         throw not_supported ();
175                 }
176
177                 protected override PropertyInfo GetPropertyImpl (string name, BindingFlags bindingAttr,
178                                                                  Binder binder, Type returnType,
179                                                                  Type[] types,
180                                                                  ParameterModifier[] modifiers)
181                 {
182                         throw not_supported ();
183                 }
184
185                 protected override bool HasElementTypeImpl ()
186                 {
187                         return false;
188                 }
189
190                 protected override bool IsArrayImpl ()
191                 {
192                         return false;
193                 }
194
195                 protected override bool IsByRefImpl ()
196                 {
197                         return false;
198                 }
199
200                 protected override bool IsCOMObjectImpl ()
201                 {
202                         return false;
203                 }
204
205                 protected override bool IsPointerImpl ()
206                 {
207                         return false;
208                 }
209
210                 protected override bool IsPrimitiveImpl ()
211                 {
212                         return false;
213                 }
214
215                 protected override bool IsValueTypeImpl ()
216                 {
217                         return base_type != null ? base_type.IsValueType : false;
218                 }
219                 
220                 public override object InvokeMember (string name, BindingFlags invokeAttr,
221                                                      Binder binder, object target, object[] args,
222                                                      ParameterModifier[] modifiers,
223                                                      CultureInfo culture, string[] namedParameters)
224                 {
225                         throw not_supported ();
226                 }
227
228                 public override Type GetElementType ()
229                 {
230                         throw not_supported ();
231                 }
232
233                 public override Type UnderlyingSystemType {
234                         get {
235                                 return this;
236                         }
237                 }
238
239                 public override Assembly Assembly {
240                         get { return tbuilder.Assembly; }
241                 }
242
243                 public override string AssemblyQualifiedName {
244                         get { return null; }
245                 }
246
247                 public override Type BaseType {
248                         get { return base_type; }
249                 }
250
251                 public override string FullName {
252                         get { return null; }
253                 }
254
255                 public override Guid GUID {
256                         get { return Guid.Empty; }
257                 }
258
259                 public override bool IsDefined (Type attributeType, bool inherit)
260                 {
261                         throw not_supported ();
262                 }
263
264                 public override object[] GetCustomAttributes (bool inherit)
265                 {
266                         throw not_supported ();
267                 }
268
269                 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
270                 {
271                         throw not_supported ();
272                 }
273
274                 public override MemberTypes MemberType {
275                         get { return MemberTypes.TypeInfo; }
276                 }
277
278                 public override string Name {
279                         get { return name; }
280                 }
281
282                 public override string Namespace {
283                         get { return null; }
284                 }
285
286                 public override Module Module {
287                         get { return tbuilder.Module; }
288                 }
289
290                 public override Type DeclaringType {
291                         get { return mbuilder != null ? null : tbuilder; }
292                 }
293
294                 public override Type ReflectedType {
295                         get {
296                                 return DeclaringType;
297                         }
298                 }
299
300                 public override RuntimeTypeHandle TypeHandle {
301                         get { throw not_supported (); }
302                 }
303
304                 public override int GetArrayRank ()
305                 {
306                         throw not_supported ();
307                 }
308
309                 public override Type[] GetGenericArguments ()
310                 {
311                         throw not_supported ();
312                 }
313
314                 public override Type GetGenericTypeDefinition ()
315                 {
316                         throw not_supported ();
317                 }
318
319                 public override bool ContainsGenericParameters {
320                         get { return true; }
321                 }
322
323                 public override bool IsGenericParameter {
324                         get { return true; }
325                 }
326
327                 public override int GenericParameterPosition {
328                         get { return index; }
329                 }
330
331                 public override GenericParameterAttributes GenericParameterAttributes {
332                         get {
333                                 return attrs;
334                         }
335                 }
336
337                 public override Type[] GetGenericParameterConstraints ()
338                 {
339                         if (base_type == null) {
340                                 if (iface_constraints != null)
341                                         return iface_constraints;
342
343                                 return Type.EmptyTypes;
344                         }
345
346                         if (iface_constraints == null)
347                                 return new Type[] { base_type };
348
349                         Type[] ret = new Type [iface_constraints.Length + 1];
350                         ret [0] = base_type;
351                         iface_constraints.CopyTo (ret, 1);
352                         return ret;
353                 }
354
355                 public override MethodInfo DeclaringMethod {
356                         get { return mbuilder; }
357                 }
358
359                 private Exception not_supported ()
360                 {
361                         return new NotSupportedException ();
362                 }
363
364                 public override string ToString ()
365                 {
366                         return name;
367                 }
368         }
369 }
370 #endif