Set svn:eol-style=native, delete svn:executable.
[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
40 namespace System.Reflection.Emit {
41         public sealed class EnumBuilder : Type {
42                 private TypeBuilder _tb;
43                 private FieldBuilder _underlyingField;
44                 private Type _underlyingType;
45
46                 internal EnumBuilder (ModuleBuilder mb, string name, TypeAttributes visibility, Type underlyingType)
47                 {
48                         _tb = new TypeBuilder (mb, name, (visibility | TypeAttributes.Sealed), 
49                                 typeof(Enum), null, PackingSize.Unspecified, 0, null);
50                         _underlyingType = underlyingType;
51                         _underlyingField = _tb.DefineField ("value__", underlyingType,
52                                 (FieldAttributes.SpecialName | FieldAttributes.Private));
53                         setup_enum_type (_tb);
54                 }
55
56                 internal TypeBuilder GetTypeBuilder ()
57                 {
58                         return _tb;
59                 }
60
61                 public override Assembly Assembly {
62                         get {
63                                 return _tb.Assembly;
64                         }
65                 }
66
67                 public override string AssemblyQualifiedName {
68                         get {
69                                 return _tb.AssemblyQualifiedName;
70                         }
71                 }
72
73                 public override Type BaseType {
74                         get {
75                                 return _tb.BaseType;
76                         }
77                 }
78
79                 public override Type DeclaringType {
80                         get {
81                                 return _tb.DeclaringType;
82                         }
83                 }
84
85                 public override string FullName {
86                         get {
87                                 return _tb.FullName;
88                         }
89                 }
90
91                 public override Guid GUID {
92                         get {
93                                 return _tb.GUID;
94                         }
95                 }
96
97                 public override Module Module {
98                         get {
99                                 return _tb.Module;
100                         }
101                 }
102
103                 public override string Name {
104                         get {
105                                 return _tb.Name;
106                         }
107                 }
108
109                 public override string Namespace {
110                         get { 
111                                 return _tb.Namespace;
112                         }
113                 }
114
115                 public override Type ReflectedType {
116                         get {
117                                 return _tb.ReflectedType;
118                         }
119                 }
120
121                 public override RuntimeTypeHandle TypeHandle {
122                         get {
123                                 return _tb.TypeHandle;
124                         }
125                 }
126
127                 public TypeToken TypeToken {
128                         get {
129                                 return _tb.TypeToken;
130                         }
131                 }
132
133                 public FieldBuilder UnderlyingField {
134                         get {
135                                 return _underlyingField;
136                         }
137                 }
138
139                 public override Type UnderlyingSystemType {
140                         get {
141                                 return _underlyingType;
142                         }
143                 }
144
145                 public Type CreateType ()
146                 {
147                         Type res = _tb.CreateType ();
148                         return res;
149                 }
150
151                 [MethodImplAttribute(MethodImplOptions.InternalCall)]
152                 private extern void setup_enum_type (Type t);
153
154                 public FieldBuilder DefineLiteral (string literalName, object literalValue)
155                 {
156                         FieldBuilder fieldBuilder = _tb.DefineField (literalName, 
157                                 _underlyingType, (FieldAttributes.Literal | 
158                                 (FieldAttributes.Static | FieldAttributes.Public)));
159                         fieldBuilder.SetConstant (literalValue);
160                         return fieldBuilder;
161                 }
162
163                 protected override TypeAttributes GetAttributeFlagsImpl ()
164                 {
165                         return _tb.attrs;
166                 }
167
168                 protected override ConstructorInfo GetConstructorImpl (
169                         BindingFlags bindingAttr, Binder binder, CallingConventions cc,
170                         Type[] types, ParameterModifier[] modifiers)
171                 {
172                         return _tb.GetConstructor (bindingAttr, binder, cc, types, 
173                                 modifiers);
174                 }
175
176                 public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
177                 {
178                         return _tb.GetConstructors (bindingAttr);
179                 }
180
181                 public override object[] GetCustomAttributes(bool inherit)
182                 {
183                         return _tb.GetCustomAttributes (inherit);
184                 }
185
186                 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
187                 {
188                         return _tb.GetCustomAttributes (attributeType, inherit);
189                 }
190
191                 public override Type GetElementType()
192                 {
193                         return _tb.GetElementType ();
194                 }
195
196                 public override EventInfo GetEvent( string name, BindingFlags bindingAttr)
197                 {
198                         return _tb.GetEvent (name, bindingAttr);
199                 }
200
201                 public override EventInfo[] GetEvents()
202                 {
203                         return _tb.GetEvents ();
204                 }
205
206                 public override EventInfo[] GetEvents( BindingFlags bindingAttr)
207                 {
208                         return _tb.GetEvents (bindingAttr);
209                 }
210
211                 public override FieldInfo GetField( string name, BindingFlags bindingAttr)
212                 {
213                         return _tb.GetField (name, bindingAttr);
214                 }
215
216                 public override FieldInfo[] GetFields( BindingFlags bindingAttr)
217                 {
218                         return _tb.GetFields (bindingAttr);
219                 }
220
221                 public override Type GetInterface (string name, bool ignoreCase)
222                 {
223                         return _tb.GetInterface (name, ignoreCase);
224                 }
225
226                 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
227                 {
228                         return _tb.GetInterfaceMap (interfaceType);
229                 }
230
231                 public override Type[] GetInterfaces()
232                 {
233                         return _tb.GetInterfaces ();
234                 }
235
236                 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
237                 {
238                         return _tb.GetMember (name, type, bindingAttr);
239                 }
240
241                 public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
242                 {
243                         return _tb.GetMembers (bindingAttr);
244                 }
245
246                 protected override MethodInfo GetMethodImpl (
247                         string name, BindingFlags bindingAttr, Binder binder,
248                         CallingConventions callConvention, Type[] types,
249                         ParameterModifier[] modifiers)
250                 {
251                         if (types == null) {
252                                 return _tb.GetMethod (name, bindingAttr);
253                         }
254
255                         return _tb.GetMethod (name, bindingAttr, binder, 
256                                 callConvention, types, modifiers);
257                 }
258
259                 public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
260                 {
261                         return _tb.GetMethods (bindingAttr);
262                 }
263
264                 public override Type GetNestedType (string name, BindingFlags bindingAttr)
265                 {
266                         return _tb.GetNestedType (name, bindingAttr);
267                 }
268
269                 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
270                 {
271                         return _tb.GetNestedTypes (bindingAttr);
272                 }
273
274                 public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
275                 {
276                         return _tb.GetProperties (bindingAttr);
277                 }
278
279                 protected override PropertyInfo GetPropertyImpl (
280                         string name, BindingFlags bindingAttr, Binder binder,
281                         Type returnType, Type[] types,
282                         ParameterModifier[] modifiers)
283                 {
284                         throw CreateNotSupportedException ();
285                 }
286
287                 protected override bool HasElementTypeImpl ()
288                 {
289                         return _tb.HasElementType;
290                 }
291
292                 public override object InvokeMember (
293                         string name, BindingFlags invokeAttr, Binder binder,
294                         object target, object[] args,
295                         ParameterModifier[] modifiers, CultureInfo culture,
296                         string[] namedParameters)
297                 {
298                         return _tb.InvokeMember (name, invokeAttr, binder, target, 
299                                 args, modifiers, culture, namedParameters);
300                 }
301
302                 protected override bool IsArrayImpl()
303                 {
304                         return false;
305                 }
306
307                 protected override bool IsByRefImpl()
308                 {
309                         return false;
310                 }
311
312                 protected override bool IsCOMObjectImpl()
313                 {
314                         return false;
315                 }
316
317                 protected override bool IsPointerImpl()
318                 {
319                         return false;
320                 }
321
322                 protected override bool IsPrimitiveImpl()
323                 {
324                         return false;
325                 }
326
327                 protected override bool IsValueTypeImpl()
328                 {
329                         return true;
330                 }
331
332                 public override bool IsDefined (Type attributeType, bool inherit)
333                 {
334                         return _tb.IsDefined (attributeType, inherit);
335                 }
336
337                 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
338                 {
339                         _tb.SetCustomAttribute (customBuilder);
340                 }
341
342                 public void SetCustomAttribute (ConstructorInfo con, byte[] binaryAttribute)
343                 {
344                         SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
345                 }
346
347 #if NET_2_0 || BOOTSTRAP_NET_2_0
348                 [MonoTODO]
349                 public override Type[] GetGenericArguments ()
350                 {
351                         throw new NotImplementedException ();
352                 }
353
354                 [MonoTODO]
355                 public override bool HasGenericArguments {
356                         get {
357                                 throw new NotImplementedException ();
358                         }
359                 }
360
361                 [MonoTODO]
362                 public override bool ContainsGenericParameters {
363                         get {
364                                 throw new NotImplementedException ();
365                         }
366                 }
367
368                 [MonoTODO]
369                 public override bool IsGenericParameter {
370                         get {
371                                 throw new NotImplementedException ();
372                         }
373                 }
374
375                 [MonoTODO]
376                 public override int GenericParameterPosition {
377                         get {
378                                 throw new NotImplementedException ();
379                         }
380                 }
381
382                 [MonoTODO]
383                 public override MethodInfo DeclaringMethod {
384                         get {
385                                 throw new NotImplementedException ();
386                         }
387                 }
388 #endif
389
390                 private Exception CreateNotSupportedException ()
391                 {
392                         return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
393                 }
394         }
395 }