public DefineEnum ( string name, System visibility, System underlyingType ) : System.Reflection.Emit.EnumBuilder | ||
name | string | |
visibility | System | |
underlyingType | System | |
return | System.Reflection.Emit.EnumBuilder |
private static Type BuildEnum(ITypeDescription typeInfo, IDictionary<ITypeDescription, Type> typeBuildMap, ModuleBuilder modBuilder) { var enumBuilder = modBuilder.DefineEnum(BuildName(typeInfo.TypeName), TypeAttributes.Class | TypeAttributes.Public, typeof(int)); typeBuildMap[typeInfo] = enumBuilder; for (int i = -EnumRange; i < EnumRange; i++) { if(i<0) { enumBuilder.DefineLiteral("Value_Negative" + Math.Abs(i),i); } else { enumBuilder.DefineLiteral("Value_" + Math.Abs(i), i); } } return enumBuilder.CreateType(); }
private static EnumBuilder GenerateEnum (ModuleBuilder modBuilder) { return modBuilder.DefineEnum (_enumNamespace + "." + _enumName, TypeAttributes.Public, _enumType); }
private static Type CreateEnumType(ModuleBuilder builder, Random rand, string id) { var name = builder.Assembly.GetName().Name + ".EnumType" + id; EnumBuilder enumBuilder = builder.DefineEnum(name, TypeAttributes.Public, typeof(int)); // define 1~10 literal in the enum for (int i = 0; i < rand.Next(10) + 1; i++) { enumBuilder.DefineLiteral("Literal" + i, i); } var result = enumBuilder.CreateType(); return result; }
private Type GenerateEnumeration(string name, string[] values, ModuleBuilder moduleBuilder) { EnumBuilder enumBuilder = moduleBuilder.DefineEnum(name, TypeAttributes.Public, typeof(int)); int position = 0; foreach (string value in values) { enumBuilder.DefineLiteral(value, position++); } return enumBuilder.CreateType(); }
private static Type CreateEnum(ModuleBuilder moduleBuilder, EnumTypeElement element) { var typeName = element.ResolveName(); var underlyingType = ConvertType(element.UnderlyingType); var typeBuilder = moduleBuilder.DefineEnum(typeName, underlyingType); foreach (var member in element.Members) { typeBuilder.DefineLiteral(member.Key, Convert.ChangeType(member.Value, underlyingType)); } return typeBuilder.CreateType(); }
public Type CreateEnumType(ModuleBuilder mb, Random rndGen, string typeID) { var name = mb.Assembly.GetName().Name + ".EnumType" + typeID; var eb = mb.DefineEnum(name, TypeAttributes.Public, typeof(int)); for (int i = 0; i < rndGen.Next(10) + 1; i++) { eb.DefineLiteral("Literal" + i, i); } var result = eb.CreateType(); this.ComplexTypes.Add(result); return result; }
/// <summary> /// Runtime enum type builder /// </summary> /// <param name="moduleBuilder"></param> /// <param name="xmlNamespace"></param> /// <param name="xmlEnum"></param> /// <returns></returns> private EnumBuilder CreateRTEnumType(ModuleBuilder moduleBuilder, XmlModelNamespaceRoot xmlNamespace, XmlEnumLayout xmlEnum) { Type enumType = FactoryStandardType.Get(xmlEnum.NetType); EnumBuilder enumBuilder = moduleBuilder.DefineEnum(string.Format("{0}.{1}", xmlNamespace.Namespace, xmlEnum.Name), TypeAttributes.Public, enumType); // Foreach field foreach (XmlEnumKeyValueLayout xmlkeyValue in xmlEnum.Keys) { if (FactoryStandardType.IsNumericTypes(xmlEnum.NetType)) { enumBuilder.DefineLiteral(xmlkeyValue.Name, FactoryStandardType.ConvertToNumeric(xmlEnum.NetType, xmlkeyValue.Value, xmlEnum.NumberBase)); } } return enumBuilder; }