2 Copyright (C) 2010 Jeroen Frijters
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
25 using System.Collections.Generic;
28 namespace IKVM.Reflection.Emit
30 public sealed class EnumBuilder : Type
32 private readonly TypeBuilder typeBuilder;
33 private readonly FieldBuilder fieldBuilder;
35 internal EnumBuilder(TypeBuilder typeBuilder, FieldBuilder fieldBuilder)
38 this.typeBuilder = typeBuilder;
39 this.fieldBuilder = fieldBuilder;
42 public override string __Name
44 get { return typeBuilder.__Name; }
47 public override string __Namespace
49 get { return typeBuilder.__Namespace; }
52 public override string Name
54 get { return typeBuilder.Name; }
57 public override string FullName
59 get { return typeBuilder.FullName; }
62 public override Type BaseType
64 get { return typeBuilder.BaseType; }
67 public override TypeAttributes Attributes
69 get { return typeBuilder.Attributes; }
72 public override Module Module
74 get { return typeBuilder.Module; }
77 public FieldBuilder DefineLiteral(string literalName, object literalValue)
79 FieldBuilder fb = typeBuilder.DefineField(literalName, typeBuilder, FieldAttributes.Public | FieldAttributes.Static | FieldAttributes.Literal);
80 fb.SetConstant(literalValue);
84 public Type CreateType()
86 return typeBuilder.CreateType();
89 public TypeToken TypeToken
91 get { return typeBuilder.TypeToken; }
94 public FieldBuilder UnderlyingField
96 get { return fieldBuilder; }
99 public void SetCustomAttribute(ConstructorInfo con, byte[] binaryAttribute)
101 typeBuilder.SetCustomAttribute(con, binaryAttribute);
104 public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
106 typeBuilder.SetCustomAttribute(customBuilder);
109 public override Type GetEnumUnderlyingType()
111 return fieldBuilder.FieldType;
114 internal override bool IsBaked
116 get { return typeBuilder.IsBaked; }