3 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
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:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
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.
26 // System.Reflection.Emit/EnumBuilder.cs
29 // Paolo Molaro (lupus@ximian.com)
31 // (C) 2001 Ximian, Inc. http://www.ximian.com
35 using System.Reflection;
36 using System.Reflection.Emit;
37 using System.Globalization;
38 using System.Runtime.CompilerServices;
39 using System.Runtime.InteropServices;
41 namespace System.Reflection.Emit {
44 [ComDefaultInterface (typeof (_EnumBuilder))]
46 [ClassInterface (ClassInterfaceType.None)]
47 public sealed class EnumBuilder : Type, _EnumBuilder {
48 private TypeBuilder _tb;
49 private FieldBuilder _underlyingField;
50 private Type _underlyingType;
52 internal EnumBuilder (ModuleBuilder mb, string name, TypeAttributes visibility, Type underlyingType)
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);
62 internal TypeBuilder GetTypeBuilder ()
67 public override Assembly Assembly {
73 public override string AssemblyQualifiedName {
75 return _tb.AssemblyQualifiedName;
79 public override Type BaseType {
85 public override Type DeclaringType {
87 return _tb.DeclaringType;
91 public override string FullName {
97 public override Guid GUID {
103 public override Module Module {
109 public override string Name {
115 public override string Namespace {
117 return _tb.Namespace;
121 public override Type ReflectedType {
123 return _tb.ReflectedType;
127 public override RuntimeTypeHandle TypeHandle {
129 return _tb.TypeHandle;
133 public TypeToken TypeToken {
135 return _tb.TypeToken;
139 public FieldBuilder UnderlyingField {
141 return _underlyingField;
145 public override Type UnderlyingSystemType {
147 return _underlyingType;
151 public Type CreateType ()
153 Type res = _tb.CreateType ();
157 [MethodImplAttribute(MethodImplOptions.InternalCall)]
158 private extern void setup_enum_type (Type t);
160 public FieldBuilder DefineLiteral (string literalName, object literalValue)
162 FieldBuilder fieldBuilder = _tb.DefineField (literalName,
163 _underlyingType, (FieldAttributes.Literal |
164 (FieldAttributes.Static | FieldAttributes.Public)));
165 fieldBuilder.SetConstant (literalValue);
169 protected override TypeAttributes GetAttributeFlagsImpl ()
174 protected override ConstructorInfo GetConstructorImpl (
175 BindingFlags bindingAttr, Binder binder, CallingConventions cc,
176 Type[] types, ParameterModifier[] modifiers)
178 return _tb.GetConstructor (bindingAttr, binder, cc, types,
182 public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
184 return _tb.GetConstructors (bindingAttr);
187 public override object[] GetCustomAttributes(bool inherit)
189 return _tb.GetCustomAttributes (inherit);
192 public override object[] GetCustomAttributes(Type attributeType, bool inherit)
194 return _tb.GetCustomAttributes (attributeType, inherit);
197 public override Type GetElementType()
199 return _tb.GetElementType ();
202 public override EventInfo GetEvent( string name, BindingFlags bindingAttr)
204 return _tb.GetEvent (name, bindingAttr);
207 public override EventInfo[] GetEvents()
209 return _tb.GetEvents ();
212 public override EventInfo[] GetEvents( BindingFlags bindingAttr)
214 return _tb.GetEvents (bindingAttr);
217 public override FieldInfo GetField( string name, BindingFlags bindingAttr)
219 return _tb.GetField (name, bindingAttr);
222 public override FieldInfo[] GetFields( BindingFlags bindingAttr)
224 return _tb.GetFields (bindingAttr);
227 public override Type GetInterface (string name, bool ignoreCase)
229 return _tb.GetInterface (name, ignoreCase);
232 public override InterfaceMapping GetInterfaceMap (Type interfaceType)
234 return _tb.GetInterfaceMap (interfaceType);
237 public override Type[] GetInterfaces()
239 return _tb.GetInterfaces ();
242 public override MemberInfo[] GetMember (string name, MemberTypes type, BindingFlags bindingAttr)
244 return _tb.GetMember (name, type, bindingAttr);
247 public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
249 return _tb.GetMembers (bindingAttr);
252 protected override MethodInfo GetMethodImpl (
253 string name, BindingFlags bindingAttr, Binder binder,
254 CallingConventions callConvention, Type[] types,
255 ParameterModifier[] modifiers)
258 return _tb.GetMethod (name, bindingAttr);
261 return _tb.GetMethod (name, bindingAttr, binder,
262 callConvention, types, modifiers);
265 public override MethodInfo[] GetMethods (BindingFlags bindingAttr)
267 return _tb.GetMethods (bindingAttr);
270 public override Type GetNestedType (string name, BindingFlags bindingAttr)
272 return _tb.GetNestedType (name, bindingAttr);
275 public override Type[] GetNestedTypes (BindingFlags bindingAttr)
277 return _tb.GetNestedTypes (bindingAttr);
280 public override PropertyInfo[] GetProperties (BindingFlags bindingAttr)
282 return _tb.GetProperties (bindingAttr);
285 protected override PropertyInfo GetPropertyImpl (
286 string name, BindingFlags bindingAttr, Binder binder,
287 Type returnType, Type[] types,
288 ParameterModifier[] modifiers)
290 throw CreateNotSupportedException ();
293 protected override bool HasElementTypeImpl ()
295 return _tb.HasElementType;
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)
304 return _tb.InvokeMember (name, invokeAttr, binder, target,
305 args, modifiers, culture, namedParameters);
308 protected override bool IsArrayImpl()
313 protected override bool IsByRefImpl()
318 protected override bool IsCOMObjectImpl()
323 protected override bool IsPointerImpl()
328 protected override bool IsPrimitiveImpl()
333 protected override bool IsValueTypeImpl()
338 public override bool IsDefined (Type attributeType, bool inherit)
340 return _tb.IsDefined (attributeType, inherit);
343 public void SetCustomAttribute (CustomAttributeBuilder customBuilder)
345 _tb.SetCustomAttribute (customBuilder);
351 public void SetCustomAttribute (ConstructorInfo con, byte[] binaryAttribute)
353 SetCustomAttribute (new CustomAttributeBuilder (con, binaryAttribute));
356 #if NET_2_0 || BOOTSTRAP_NET_2_0
358 public override Type[] GetGenericArguments ()
360 throw new NotImplementedException ();
364 public override bool ContainsGenericParameters {
366 throw new NotImplementedException ();
371 public override bool IsGenericParameter {
373 throw new NotImplementedException ();
378 public override int GenericParameterPosition {
380 throw new NotImplementedException ();
385 public override MethodInfo DeclaringMethod {
387 throw new NotImplementedException ();
392 private Exception CreateNotSupportedException ()
394 return new NotSupportedException ("The invoked member is not supported in a dynamic module.");
397 void _EnumBuilder.GetIDsOfNames ([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
399 throw new NotImplementedException ();
402 void _EnumBuilder.GetTypeInfo (uint iTInfo, uint lcid, IntPtr ppTInfo)
404 throw new NotImplementedException ();
407 void _EnumBuilder.GetTypeInfoCount (out uint pcTInfo)
409 throw new NotImplementedException ();
412 void _EnumBuilder.Invoke (uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
414 throw new NotImplementedException ();