* Mono.Posix.dll.sources: Rename Mono.Posix to Mono.Unix.
[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 #warning "FIXME"
215                         return false;
216                         // return base_type != null ? base_type.IsValueType : false;
217                 }
218                 
219                 public override object InvokeMember (string name, BindingFlags invokeAttr,
220                                                      Binder binder, object target, object[] args,
221                                                      ParameterModifier[] modifiers,
222                                                      CultureInfo culture, string[] namedParameters)
223                 {
224                         throw not_supported ();
225                 }
226
227                 public override Type GetElementType ()
228                 {
229                         throw not_supported ();
230                 }
231
232                 public override Type UnderlyingSystemType {
233                         get {
234                                 return null;
235                         }
236                 }
237
238                 public override Assembly Assembly {
239                         get { return tbuilder.Assembly; }
240                 }
241
242                 public override string AssemblyQualifiedName {
243                         get { return null; }
244                 }
245
246                 public override Type BaseType {
247                         get { return base_type; }
248                 }
249
250                 public override string FullName {
251                         get { return null; }
252                 }
253
254                 public override Guid GUID {
255                         get { return Guid.Empty; }
256                 }
257
258                 public override bool IsDefined (Type attributeType, bool inherit)
259                 {
260                         throw not_supported ();
261                 }
262
263                 public override object[] GetCustomAttributes (bool inherit)
264                 {
265                         throw not_supported ();
266                 }
267
268                 public override object[] GetCustomAttributes (Type attributeType, bool inherit)
269                 {
270                         throw not_supported ();
271                 }
272
273                 public override MemberTypes MemberType {
274                         get { return MemberTypes.TypeInfo; }
275                 }
276
277                 public override string Name {
278                         get { return name; }
279                 }
280
281                 public override string Namespace {
282                         get { return null; }
283                 }
284
285                 public override Module Module {
286                         get { return tbuilder.Module; }
287                 }
288
289                 public override Type DeclaringType {
290                         get { return mbuilder != null ? null : tbuilder; }
291                 }
292
293                 public override Type ReflectedType {
294                         get {
295                                 return DeclaringType;
296                         }
297                 }
298
299                 public override RuntimeTypeHandle TypeHandle {
300                         get { throw not_supported (); }
301                 }
302
303                 public override int GetArrayRank ()
304                 {
305                         throw not_supported ();
306                 }
307
308                 public override Type[] GetGenericArguments ()
309                 {
310                         throw not_supported ();
311                 }
312
313                 public override Type GetGenericTypeDefinition ()
314                 {
315                         throw not_supported ();
316                 }
317
318                 public override bool HasGenericArguments {
319                         get { return false; }
320                 }
321
322                 public override bool ContainsGenericParameters {
323                         get { return true; }
324                 }
325
326                 public override bool IsGenericParameter {
327                         get { return true; }
328                 }
329
330                 public override int GenericParameterPosition {
331                         get { return index; }
332                 }
333
334                 public override GenericParameterAttributes GenericParameterAttributes {
335                         get {
336                                 return attrs;
337                         }
338                 }
339
340                 public override Type[] GetGenericParameterConstraints ()
341                 {
342                         if (base_type == null) {
343                                 if (iface_constraints != null)
344                                         return iface_constraints;
345
346                                 return Type.EmptyTypes;
347                         }
348
349                         if (iface_constraints == null)
350                                 return new Type[] { base_type };
351
352                         Type[] ret = new Type [iface_constraints.Length + 1];
353                         ret [0] = base_type;
354                         iface_constraints.CopyTo (ret, 1);
355                         return ret;
356                 }
357
358                 public override MethodInfo DeclaringMethod {
359                         get { return mbuilder; }
360                 }
361
362                 private Exception not_supported ()
363                 {
364                         return new NotSupportedException ();
365                 }
366
367                 public override string ToString ()
368                 {
369                         return name;
370                 }
371         }
372 }
373 #endif