mscorlib(4.0.0.0) API with additions
EnumBuilder.cs
3 using System.Security;
5 
7 {
9  [ClassInterface(ClassInterfaceType.None)]
10  [ComDefaultInterface(typeof(_EnumBuilder))]
11  [ComVisible(true)]
12  [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
13  public sealed class EnumBuilder : TypeInfo, _EnumBuilder
14  {
15  internal TypeBuilder m_typeBuilder;
16 
17  private FieldBuilder m_underlyingField;
18 
21  public TypeToken TypeToken => m_typeBuilder.TypeToken;
22 
25  public FieldBuilder UnderlyingField => m_underlyingField;
26 
29  public override string Name => m_typeBuilder.Name;
30 
34  public override Guid GUID => m_typeBuilder.GUID;
35 
38  public override Module Module => m_typeBuilder.Module;
39 
42  public override Assembly Assembly => m_typeBuilder.Assembly;
43 
47  public override RuntimeTypeHandle TypeHandle => m_typeBuilder.TypeHandle;
48 
51  public override string FullName => m_typeBuilder.FullName;
52 
55  public override string AssemblyQualifiedName => m_typeBuilder.AssemblyQualifiedName;
56 
59  public override string Namespace => m_typeBuilder.Namespace;
60 
63  public override Type BaseType => m_typeBuilder.BaseType;
64 
68  public override bool IsConstructedGenericType => false;
69 
73 
76  public override Type DeclaringType => m_typeBuilder.DeclaringType;
77 
80  public override Type ReflectedType => m_typeBuilder.ReflectedType;
81 
82  internal int MetadataTokenInternal => m_typeBuilder.MetadataTokenInternal;
83 
88  public override bool IsAssignableFrom(TypeInfo typeInfo)
89  {
90  if (typeInfo == null)
91  {
92  return false;
93  }
94  return IsAssignableFrom(typeInfo.AsType());
95  }
96 
101  public FieldBuilder DefineLiteral(string literalName, object literalValue)
102  {
103  FieldBuilder fieldBuilder = m_typeBuilder.DefineField(literalName, this, FieldAttributes.FamANDAssem | FieldAttributes.Family | FieldAttributes.Static | FieldAttributes.Literal);
104  fieldBuilder.SetConstant(literalValue);
105  return fieldBuilder;
106  }
107 
111  {
112  return m_typeBuilder.CreateTypeInfo();
113  }
114 
118  public Type CreateType()
119  {
120  return m_typeBuilder.CreateType();
121  }
122 
134  public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
135  {
136  return m_typeBuilder.InvokeMember(name, invokeAttr, binder, target, args, modifiers, culture, namedParameters);
137  }
138 
139  protected override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
140  {
141  return m_typeBuilder.GetConstructor(bindingAttr, binder, callConvention, types, modifiers);
142  }
143 
148  [ComVisible(true)]
149  public override ConstructorInfo[] GetConstructors(BindingFlags bindingAttr)
150  {
151  return m_typeBuilder.GetConstructors(bindingAttr);
152  }
153 
154  protected override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
155  {
156  if (types == null)
157  {
158  return m_typeBuilder.GetMethod(name, bindingAttr);
159  }
160  return m_typeBuilder.GetMethod(name, bindingAttr, binder, callConvention, types, modifiers);
161  }
162 
167  public override MethodInfo[] GetMethods(BindingFlags bindingAttr)
168  {
169  return m_typeBuilder.GetMethods(bindingAttr);
170  }
171 
177  public override FieldInfo GetField(string name, BindingFlags bindingAttr)
178  {
179  return m_typeBuilder.GetField(name, bindingAttr);
180  }
181 
186  public override FieldInfo[] GetFields(BindingFlags bindingAttr)
187  {
188  return m_typeBuilder.GetFields(bindingAttr);
189  }
190 
196  public override Type GetInterface(string name, bool ignoreCase)
197  {
198  return m_typeBuilder.GetInterface(name, ignoreCase);
199  }
200 
203  public override Type[] GetInterfaces()
204  {
205  return m_typeBuilder.GetInterfaces();
206  }
207 
213  public override EventInfo GetEvent(string name, BindingFlags bindingAttr)
214  {
215  return m_typeBuilder.GetEvent(name, bindingAttr);
216  }
217 
221  public override EventInfo[] GetEvents()
222  {
223  return m_typeBuilder.GetEvents();
224  }
225 
226  protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
227  {
228  throw new NotSupportedException(Environment.GetResourceString("NotSupported_DynamicModule"));
229  }
230 
235  public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
236  {
237  return m_typeBuilder.GetProperties(bindingAttr);
238  }
239 
244  public override Type[] GetNestedTypes(BindingFlags bindingAttr)
245  {
246  return m_typeBuilder.GetNestedTypes(bindingAttr);
247  }
248 
254  public override Type GetNestedType(string name, BindingFlags bindingAttr)
255  {
256  return m_typeBuilder.GetNestedType(name, bindingAttr);
257  }
258 
265  public override MemberInfo[] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
266  {
267  return m_typeBuilder.GetMember(name, type, bindingAttr);
268  }
269 
274  public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
275  {
276  return m_typeBuilder.GetMembers(bindingAttr);
277  }
278 
283  [ComVisible(true)]
284  public override InterfaceMapping GetInterfaceMap(Type interfaceType)
285  {
286  return m_typeBuilder.GetInterfaceMap(interfaceType);
287  }
288 
293  public override EventInfo[] GetEvents(BindingFlags bindingAttr)
294  {
295  return m_typeBuilder.GetEvents(bindingAttr);
296  }
297 
299  {
300  return m_typeBuilder.Attributes;
301  }
302 
303  protected override bool IsArrayImpl()
304  {
305  return false;
306  }
307 
308  protected override bool IsPrimitiveImpl()
309  {
310  return false;
311  }
312 
313  protected override bool IsValueTypeImpl()
314  {
315  return true;
316  }
317 
318  protected override bool IsByRefImpl()
319  {
320  return false;
321  }
322 
323  protected override bool IsPointerImpl()
324  {
325  return false;
326  }
327 
328  protected override bool IsCOMObjectImpl()
329  {
330  return false;
331  }
332 
336  public override Type GetElementType()
337  {
338  return m_typeBuilder.GetElementType();
339  }
340 
341  protected override bool HasElementTypeImpl()
342  {
343  return m_typeBuilder.HasElementType;
344  }
345 
348  public override Type GetEnumUnderlyingType()
349  {
350  return m_underlyingField.FieldType;
351  }
352 
357  public override object[] GetCustomAttributes(bool inherit)
358  {
359  return m_typeBuilder.GetCustomAttributes(inherit);
360  }
361 
367  public override object[] GetCustomAttributes(Type attributeType, bool inherit)
368  {
369  return m_typeBuilder.GetCustomAttributes(attributeType, inherit);
370  }
371 
377  [ComVisible(true)]
378  public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
379  {
380  m_typeBuilder.SetCustomAttribute(con, binaryAttribute);
381  }
382 
387  public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
388  {
389  m_typeBuilder.SetCustomAttribute(customBuilder);
390  }
391 
398  public override bool IsDefined(Type attributeType, bool inherit)
399  {
400  return m_typeBuilder.IsDefined(attributeType, inherit);
401  }
402 
403  private EnumBuilder()
404  {
405  }
406 
409  public override Type MakePointerType()
410  {
411  return SymbolType.FormCompoundType("*".ToCharArray(), this, 0);
412  }
413 
416  public override Type MakeByRefType()
417  {
418  return SymbolType.FormCompoundType("&".ToCharArray(), this, 0);
419  }
420 
423  public override Type MakeArrayType()
424  {
425  return SymbolType.FormCompoundType("[]".ToCharArray(), this, 0);
426  }
427 
433  public override Type MakeArrayType(int rank)
434  {
435  if (rank <= 0)
436  {
437  throw new IndexOutOfRangeException();
438  }
439  string text = "";
440  if (rank == 1)
441  {
442  text = "*";
443  }
444  else
445  {
446  for (int i = 1; i < rank; i++)
447  {
448  text += ",";
449  }
450  }
451  string text2 = string.Format(CultureInfo.InvariantCulture, "[{0}]", text);
452  return SymbolType.FormCompoundType(text2.ToCharArray(), this, 0);
453  }
454 
455  [SecurityCritical]
456  internal EnumBuilder(string name, Type underlyingType, TypeAttributes visibility, ModuleBuilder module)
457  {
458  if ((visibility & ~TypeAttributes.VisibilityMask) != 0)
459  {
460  throw new ArgumentException(Environment.GetResourceString("Argument_ShouldOnlySetVisibilityFlags"), "name");
461  }
462  m_typeBuilder = new TypeBuilder(name, visibility | TypeAttributes.Sealed, typeof(Enum), null, module, PackingSize.Unspecified, 0, null);
463  m_underlyingField = m_typeBuilder.DefineField("value__", underlyingType, FieldAttributes.FamANDAssem | FieldAttributes.Family | FieldAttributes.SpecialName | FieldAttributes.RTSpecialName);
464  }
465 
469  void _EnumBuilder.GetTypeInfoCount(out uint pcTInfo)
470  {
471  throw new NotImplementedException();
472  }
473 
479  void _EnumBuilder.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
480  {
481  throw new NotImplementedException();
482  }
483 
491  void _EnumBuilder.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
492  {
493  throw new NotImplementedException();
494  }
495 
506  void _EnumBuilder.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
507  {
508  throw new NotImplementedException();
509  }
510  }
511 }
Obtains information about the attributes of a member and provides access to member metadata.
Definition: MemberInfo.cs:14
abstract Type BaseType
Gets the type from which the current T:System.Type directly inherits.
Definition: Type.cs:180
Performs reflection on a module.
Definition: Module.cs:17
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
override bool IsPrimitiveImpl()
When overridden in a derived class, implements the P:System.Type.IsPrimitive property and determines ...
Definition: EnumBuilder.cs:308
override Type UnderlyingSystemType
Returns the underlying system type for this enum.
Definition: EnumBuilder.cs:72
Type [] GetNestedTypes()
Returns the public types nested in the current T:System.Type.
Definition: Type.cs:2020
Describes and represents an enumeration type.
Definition: EnumBuilder.cs:13
abstract Type GetElementType()
When overridden in a derived class, returns the T:System.Type of the object encompassed or referred t...
Type GetInterface(string name)
Searches for the interface with the specified name.
Definition: Type.cs:1712
override Type ReflectedType
Gets the class object that was used to obtain this member.
Definition: Type.cs:80
override bool IsDefined(Type attributeType, bool inherit)
Checks if the specified custom attribute type is defined.
Definition: EnumBuilder.cs:398
Discovers the attributes of a method and provides access to method metadata.
Definition: MethodInfo.cs:13
override Type DeclaringType
Returns the type that declared this T:System.Reflection.Emit.EnumBuilder.
Definition: EnumBuilder.cs:76
override string AssemblyQualifiedName
Returns the full path of this enum qualified by the display name of the parent assembly.
Definition: EnumBuilder.cs:55
override RuntimeTypeHandle TypeHandle
Retrieves the internal handle for this enum.
Definition: EnumBuilder.cs:47
Discovers the attributes of a class constructor and provides access to constructor metadata.
void SetCustomAttribute(CustomAttributeBuilder customBuilder)
Sets a custom attribute using a custom attribute builder.
Definition: EnumBuilder.cs:387
Discovers the attributes of a field and provides access to field metadata.
Definition: FieldInfo.cs:15
BindingFlags
Specifies flags that control binding and the way in which the search for members and types is conduct...
Definition: BindingFlags.cs:10
Type GetNestedType(string name)
Searches for the public nested type with the specified name.
Definition: Type.cs:2036
Definition: __Canon.cs:3
override Type GetElementType()
Calling this method always throws T:System.NotSupportedException.
Definition: EnumBuilder.cs:336
override MethodInfo [] GetMethods(BindingFlags bindingAttr)
Returns all the public and non-public methods declared or inherited by this type, as specified.
Definition: EnumBuilder.cs:167
Type CreateType()
Creates a T:System.Type object for this enum.
Definition: EnumBuilder.cs:118
override bool IsAssignableFrom(TypeInfo typeInfo)
Gets a value that indicates whether a specified T:System.Reflection.TypeInfo object can be assigned t...
Definition: EnumBuilder.cs:88
Represents a type using an internal metadata token.
override Type DeclaringType
Gets the type that declares the current nested type or generic type parameter.
Definition: Type.cs:54
override bool IsConstructedGenericType
Gets a value that indicates whether this object represents a constructed generic type.
Definition: EnumBuilder.cs:68
void GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
Retrieves the type information for an object, which can be used to get the type information for an in...
override bool HasElementTypeImpl()
When overridden in a derived class, implements the P:System.Type.HasElementType property and determin...
Definition: EnumBuilder.cs:341
override string FullName
Returns the full path of this enum.
Definition: EnumBuilder.cs:51
Represents type declarations for class types, interface types, array types, value types,...
Definition: TypeInfo.cs:11
Attaches a modifier to parameters so that binding can work with parameter signatures in which the typ...
override FieldInfo [] GetFields(BindingFlags bindingAttr)
Returns the public and non-public fields that are declared by this type.
Definition: EnumBuilder.cs:186
void GetTypeInfoCount(out uint pcTInfo)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).
Defines and represents a field. This class cannot be inherited.
Definition: FieldBuilder.cs:13
override object [] GetCustomAttributes(Type attributeType, bool inherit)
Returns the custom attributes identified by the given type.
Definition: EnumBuilder.cs:367
override bool IsCOMObjectImpl()
When overridden in a derived class, implements the P:System.Type.IsCOMObject property and determines ...
Definition: EnumBuilder.cs:328
override bool IsArrayImpl()
When overridden in a derived class, implements the P:System.Type.IsArray property and determines whet...
Definition: EnumBuilder.cs:303
CallingConventions
Defines the valid calling conventions for a method.
SecurityAction
Specifies the security actions that can be performed using declarative security.
override Type ReflectedType
Returns the type that was used to obtain this T:System.Reflection.Emit.EnumBuilder.
Definition: EnumBuilder.cs:80
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Definition: Guid.cs:14
override Guid GUID
Returns the GUID of this enum.
Definition: EnumBuilder.cs:34
override bool IsPointerImpl()
When overridden in a derived class, implements the P:System.Type.IsPointer property and determines wh...
Definition: EnumBuilder.cs:323
override Type GetInterface(string name, bool ignoreCase)
Returns the interface implemented (directly or indirectly) by this type, with the specified fully-qua...
Definition: EnumBuilder.cs:196
override Type MakeByRefType()
Returns a T:System.Type object that represents the current type when passed as a ref parameter (ByRef...
Definition: EnumBuilder.cs:416
The exception that is thrown when an attempt is made to access an element of an array or collection w...
override FieldInfo GetField(string name, BindingFlags bindingAttr)
Returns the field specified by the given name.
Definition: EnumBuilder.cs:177
Defines and creates new instances of classes during run time.
Definition: TypeBuilder.cs:15
override MemberInfo [] GetMembers(BindingFlags bindingAttr)
Returns the specified members declared or inherited by this type,.
Definition: EnumBuilder.cs:274
Provides the base class for enumerations.
Definition: Enum.cs:14
PackingSize
Specifies one of two factors that determine the memory alignment of fields when a type is marshaled.
Definition: PackingSize.cs:9
Defines and represents a module in a dynamic assembly.
FieldAttributes
Specifies flags that describe the attributes of a field.
FieldBuilder DefineLiteral(string literalName, object literalValue)
Defines the named static field in an enumeration type with the specified constant value.
Definition: EnumBuilder.cs:101
Retrieves the mapping of an interface into the actual methods on a class that implements that interfa...
virtual Type AsType()
Returns the current type as a T:System.Type object.
Definition: TypeInfo.cs:145
override Type BaseType
Returns the parent T:System.Type of this type which is always T:System.Enum.
Definition: EnumBuilder.cs:63
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
Discovers the attributes of an event and provides access to event metadata.
Definition: EventInfo.cs:15
override EventInfo GetEvent(string name, BindingFlags bindingAttr)
Returns the event with the specified name.
Definition: EnumBuilder.cs:213
TypeInfo CreateTypeInfo()
Gets a T:System.Reflection.TypeInfo object that represents this enumeration.
Definition: EnumBuilder.cs:110
Represents the Token returned by the metadata to represent a type.
Definition: TypeToken.cs:8
Represents type declarations: class types, interface types, array types, value types,...
Definition: Type.cs:18
override bool IsValueTypeImpl()
Implements the P:System.Type.IsValueType property and determines whether the T:System....
Definition: EnumBuilder.cs:313
override ConstructorInfo GetConstructorImpl(BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
When overridden in a derived class, searches for a constructor whose parameters match the specified a...
Definition: EnumBuilder.cs:139
override Type GetEnumUnderlyingType()
Returns the underlying integer type of the current enumeration, which is set when the enumeration bui...
Definition: EnumBuilder.cs:348
override Type MakeArrayType(int rank)
Returns a T:System.Type object representing an array of the current type, with the specified number o...
Definition: EnumBuilder.cs:433
abstract Type [] GetInterfaces()
When overridden in a derived class, gets all the interfaces implemented or inherited by the current T...
FieldBuilder UnderlyingField
Returns the underlying field for this enum.
Definition: EnumBuilder.cs:25
override Type [] GetInterfaces()
Returns an array of all the interfaces implemented on this a class and its base classes.
Definition: EnumBuilder.cs:203
Selects a member from a list of candidates, and performs type conversion from actual argument type to...
Definition: Binder.cs:10
TypeAttributes
Specifies type attributes.
override InterfaceMapping GetInterfaceMap(Type interfaceType)
Returns an interface mapping for the interface requested.
Definition: EnumBuilder.cs:284
override string Name
Returns the name of this enum.
Definition: EnumBuilder.cs:29
Discovers the attributes of a property and provides access to property metadata.
Definition: PropertyInfo.cs:15
override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
When overridden in a derived class, searches for the specified property whose parameters match the sp...
Definition: EnumBuilder.cs:226
void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
Sets a custom attribute using a specified custom attribute blob.
Definition: EnumBuilder.cs:378
The exception that is thrown when one of the arguments provided to a method is not valid.
Exposes the T:System.Reflection.Emit.EnumBuilder class to unmanaged code.
Definition: _EnumBuilder.cs:11
override string Namespace
Returns the namespace of this enum.
Definition: EnumBuilder.cs:59
override object [] GetCustomAttributes(bool inherit)
Returns all the custom attributes defined for this constructor.
Definition: EnumBuilder.cs:357
void Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
Provides access to properties and methods exposed by an object.
override Type MakePointerType()
Returns a T:System.Type object that represents a pointer to the current type.
Definition: EnumBuilder.cs:409
void SetConstant(object defaultValue)
Sets the default value of this field.
override ConstructorInfo [] GetConstructors(BindingFlags bindingAttr)
Returns an array of T:System.Reflection.ConstructorInfo objects representing the public and non-publi...
Definition: EnumBuilder.cs:149
override EventInfo [] GetEvents()
Returns the events for the public events declared or inherited by this type.
Definition: EnumBuilder.cs:221
override bool IsByRefImpl()
When overridden in a derived class, implements the P:System.Type.IsByRef property and determines whet...
Definition: EnumBuilder.cs:318
override MemberInfo [] GetMember(string name, MemberTypes type, BindingFlags bindingAttr)
Returns all members with the specified name, type, and binding that are declared or inherited by this...
Definition: EnumBuilder.cs:265
override Type FieldType
Indicates the T:System.Type object that represents the type of this field. This property is read-only...
Definition: FieldBuilder.cs:67
ClassInterfaceType
Identifies the type of class interface that is generated for a class.
override PropertyInfo [] GetProperties(BindingFlags bindingAttr)
Returns all the public and non-public properties declared or inherited by this type,...
Definition: EnumBuilder.cs:235
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
void GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
Maps a set of names to a corresponding set of dispatch identifiers.
MemberTypes
Marks each type of member that is defined as a derived class of T:System.Reflection....
Definition: MemberTypes.cs:9
override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, CultureInfo culture, string[] namedParameters)
Invokes the specified member. The method that is to be invoked must be accessible and provide the mos...
Definition: EnumBuilder.cs:134
override Type [] GetNestedTypes(BindingFlags bindingAttr)
Returns the public and non-public nested types that are declared or inherited by this type.
Definition: EnumBuilder.cs:244
The exception that is thrown when a requested method or operation is not implemented.
override Type MakeArrayType()
Returns a T:System.Type object representing a one-dimensional array of the current type,...
Definition: EnumBuilder.cs:423
override EventInfo [] GetEvents(BindingFlags bindingAttr)
Returns the public and non-public events that are declared by this type.
Definition: EnumBuilder.cs:293
override MethodInfo GetMethodImpl(string name, BindingFlags bindingAttr, Binder binder, CallingConventions callConvention, Type[] types, ParameterModifier[] modifiers)
When overridden in a derived class, searches for the specified method whose parameters match the spec...
Definition: EnumBuilder.cs:154
override TypeAttributes GetAttributeFlagsImpl()
When overridden in a derived class, implements the P:System.Type.Attributes property and gets a bitma...
Definition: EnumBuilder.cs:298
override Type GetNestedType(string name, BindingFlags bindingAttr)
Returns the specified nested type that is declared by this type.
Definition: EnumBuilder.cs:254