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