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