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