Reflect latest generics API changes in the August CTP.
[mono.git] / mcs / class / corlib / System.Reflection.Emit / EnumBuilder.cs
1
2 //
3 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
12 // 
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 // 
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24
25 //
26 // System.Reflection.Emit/EnumBuilder.cs
27 //
28 // Author:
29 //   Paolo Molaro (lupus@ximian.com)
30 //
31 // (C) 2001 Ximian, Inc.  http://www.ximian.com
32 //
33
34 using System;
35 using System.Reflection;
36 using System.Reflection.Emit;
37 using System.Globalization;
38 using System.Runtime.CompilerServices;
39 using System.Runtime.InteropServices;
40
41 namespace System.Reflection.Emit {
42 #if NET_2_0
43         [ComVisible (true)]
44         [ComDefaultInterface (typeof (_EnumBuilder))]
45 #endif
46         [ClassInterface (ClassInterfaceType.None)]
47         public sealed class EnumBuilder : Type, _EnumBuilder {
48                 private TypeBuilder _tb;
49                 private FieldBuilder _underlyingField;
50                 private Type _underlyingType;
51
52                 internal EnumBuilder (ModuleBuilder mb, string name, TypeAttributes visibility, Type underlyingType)
53                 {
54                         _tb = new TypeBuilder (mb, name, (visibility | TypeAttributes.Sealed), 
55                                 typeof(Enum), null, PackingSize.Unspecified, 0, null);
56                         _underlyingType = underlyingType;
57                         _underlyingField = _tb.DefineField ("value__", underlyingType,
58                                 (FieldAttributes.SpecialName | FieldAttributes.Private));
59                         setup_enum_type (_tb);
60                 }
61
62                 internal TypeBuilder GetTypeBuilder ()
63                 {
64                         return _tb;
65                 }
66
67                 public override Assembly Assembly {
68                         get {
69                                 return _tb.Assembly;
70                         }
71                 }
72
73                 public override string AssemblyQualifiedName {
74                         get {
75                                 return _tb.AssemblyQualifiedName;
76                         }
77                 }
78
79                 public override Type BaseType {
80                         get {
81                                 return _tb.BaseType;
82                         }
83                 }
84
85                 public override Type DeclaringType {
86                         get {
87                                 return _tb.DeclaringType;
88                         }
89                 }
90
91                 public override string FullName {
92                         get {
93                                 return _tb.FullName;
94                         }
95                 }
96
97                 public override Guid GUID {
98                         get {
99                                 return _tb.GUID;
100                         }
101                 }
102
103                 public override Module Module {
104                         get {
105                                 return _tb.Module;
106                         }
107                 }
108
109                 public override string Name {
110                         get {
111                                 return _tb.Name;
112                         }
113                 }
114
115                 public override string Namespace {
116                         get { 
117                                 return _tb.Namespace;
118                         }
119                 }
120
121                 public override Type ReflectedType {
122                         get {
123                                 return _tb.ReflectedType;
124                         }
125                 }
126
127                 public override RuntimeTypeHandle TypeHandle {
128                         get {
129                                 return _tb.TypeHandle;
130                         }
131                 }
132
133                 public TypeToken TypeToken {
134                         get {
135                                 return _tb.TypeToken;
136                         }
137                 }
138
139                 public FieldBuilder UnderlyingField {
140                         get {
141                                 return _underlyingField;
142                         }
143                 }
144
145                 public override Type UnderlyingSystemType {
146                         get {
147                                 return _underlyingType;
148                         }
149                 }
150
151                 public Type CreateType ()
152                 {
153                         Type res = _tb.CreateType ();
154                         return res;
155                 }
156
157                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
158                 private extern void setup_enum_type (Type t);
159
160                 public FieldBuilder DefineLiteral (string literalName, object literalValue)
161                 {
162                         FieldBuilder fieldBuilder = _tb.DefineField (literalName, 
163                                 _underlyingType, (FieldAttributes.Literal | 
164                                 (FieldAttributes.Static | FieldAttributes.Public)));
165                         fieldBuilder.SetConstant (literalValue);
166                         return fieldBuilder;
167                 }
168
169                 protected override TypeAttributes GetAttributeFlagsImpl ()
170                 {
171                         return _tb.attrs;
172                 }
173
174                 protected override ConstructorInfo GetConstructorImpl (
175                         BindingFlags bindingAttr, Binder binder, CallingConventions cc,
176                         Type[] types, ParameterModifier[] modifiers)
177                 {
178                         return _tb.GetConstructor (bindingAttr, binder, cc, types, 
179                                 modifiers);
180                 }
181
182                 public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
183                 {
184                         return _tb.GetConstructors (bindingAttr);
185                 }
186
187                 public override object[] GetCustomAttributes(bool inherit)
188                 {
189                         return _tb.GetCustomAttributes (inherit);
190                 }
191
192                 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
193                 {
194                         return _tb.GetCustomAttributes (attributeType, inherit);
195                 }
196
197                 public override Type GetElementType()
198                 {
199                         return _tb.GetElementType ();
200                 }
201
202                 public override EventInfo GetEvent( string name, BindingFlags bindingAttr)
203                 {
204                         return _tb.GetEvent (name, bindingAttr);
205                 }
206
207                 public override EventInfo[] GetEvents()
208                 {
209                         return _tb.GetEvents ();
210                 }
211
212                 public override EventInfo[] GetEvents( BindingFlags bindingAttr)
213                 {
214                         return _tb.GetEvents (bindingAttr);
215                 }
216
217                 public override FieldInfo GetField( string name, BindingFlags bindingAttr)
218                 {
219                         return _tb.GetField (name, bindingAttr);
220                 }
221
222                 public override FieldInfo[] GetFields( BindingFlags bindingAttr)
223                 {
224                         return _tb.GetFields (bindingAttr);
225                 }
226
227                 public override Type GetInterface (string name, bool ignoreCase)
228                 {
229                         return _tb.GetInterface (name, ignoreCase);
230                 }
231
232                 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
233                 {
234                         return _tb.GetInterfaceMap (interfaceType);
235                 }
236
237                 public override Type[] GetInterfaces()
238                 {
239                         return _tb.GetInterfaces ();
240                 }
241
242                 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
243                 {
244                         return _tb.GetMember (name, type, bindingAttr);
245                 }
246
247                 public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
248                 {
249                         return _tb.GetMembers (bindingAttr);
250                 }
251
252                 protected override MethodInfo GetMethodImpl (
253                         string name, BindingFlags bindingAttr, Binder binder,
254                         CallingConventions callConvention, Type[] types,
255                         ParameterModifier[] modifiers)
256                 {
257                         if (types == null) {
258                                 return _tb.GetMethod (name, bindingAttr);
259                         }
260
261                         return _tb.GetMethod (name, bindingAttr, binder, 
262                                 callConvention, types, modifiers);
263                 }
264
265                 public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
266                 {
267                         return _tb.GetMethods (bindingAttr);
268                 }
269
270                 public override Type GetNestedType (string name, BindingFlags bindingAttr)
271                 {
272                         return _tb.GetNestedType (name, bindingAttr);
273                 }
274
275                 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
276                 {
277                         return _tb.GetNestedTypes (bindingAttr);
278                 }
279
280                 public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
281                 {
282                         return _tb.GetProperties (bindingAttr);
283                 }
284
285                 protected override PropertyInfo GetPropertyImpl (
286                         string name, BindingFlags bindingAttr, Binder binder,
287                         Type returnType, Type[] types,
288                         ParameterModifier[] modifiers)
289                 {
290                         throw CreateNotSupportedException ();
291                 }
292
293                 protected override bool HasElementTypeImpl ()
294                 {
295                         return _tb.HasElementType;
296                 }
297
298                 public override object InvokeMember (
299                         string name, BindingFlags invokeAttr, Binder binder,
300                         object target, object[] args,
301                         ParameterModifier[] modifiers, CultureInfo culture,
302                         string[] namedParameters)
303                 {
304                         return _tb.InvokeMember (name, invokeAttr, binder, target, 
305                                 args, modifiers, culture, namedParameters);
306                 }
307
308                 protected override bool IsArrayImpl()
309                 {
310                         return false;
311                 }
312
313                 protected override bool IsByRefImpl()
314                 {
315                         return false;
316                 }
317
318                 protected override bool IsCOMObjectImpl()
319                 {
320                         return false;
321                 }
322
323                 protected override bool IsPointerImpl()
324                 {
325                         return false;
326                 }
327
328                 protected override bool IsPrimitiveImpl()
329                 {
330                         return false;
331                 }
332
333                 protected override bool IsValueTypeImpl()
334                 {
335                         return true;
336                 }
337
338                 public override bool IsDefined (Type attributeType, bool inherit)
339                 {
340                         return _tb.IsDefined (attributeType, inherit);
341                 }
342
343                 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
344                 {
345                         _tb.SetCustomAttribute (customBuilder);
346                 }
347
348 #if NET_2_0
349                 [ComVisible (true)]
350 #endif
351                 public void SetCustomAttribute (ConstructorInfo con, byte[] binaryAttribute)
352                 {
353                         SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
354                 }
355
356 #if NET_2_0 || BOOTSTRAP_NET_2_0
357                 [MonoTODO]
358                 public override Type[] GetGenericArguments ()
359                 {
360                         throw new NotImplementedException ();
361                 }
362
363                 [MonoTODO]
364                 public override bool ContainsGenericParameters {
365                         get {
366                                 throw new NotImplementedException ();
367                         }
368                 }
369
370                 [MonoTODO]
371                 public override bool IsGenericParameter {
372                         get {
373                                 throw new NotImplementedException ();
374                         }
375                 }
376
377                 [MonoTODO]
378                 public override int GenericParameterPosition {
379                         get {
380                                 throw new NotImplementedException ();
381                         }
382                 }
383
384                 [MonoTODO]
385                 public override MethodInfo DeclaringMethod {
386                         get {
387                                 throw new NotImplementedException ();
388                         }
389                 }
390 #endif
391
392                 private Exception CreateNotSupportedException ()
393                 {
394                         return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
395                 }
396
397                 void _EnumBuilder.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
398                 {
399                         throw new NotImplementedException ();
400                 }
401
402                 void _EnumBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
403                 {
404                         throw new NotImplementedException ();
405                 }
406
407                 void _EnumBuilder.GetTypeInfoCount (out uint pcTInfo)
408                 {
409                         throw new NotImplementedException ();
410                 }
411
412                 void _EnumBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
413                 {
414                         throw new NotImplementedException ();
415                 }
416         }
417 }