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