本文整理汇总了C#中System.Reflection.Emit.ModuleBuilder.DefineEnum方法的典型用法代码示例。如果您正苦于以下问题:C# ModuleBuilder.DefineEnum方法的具体用法?C# ModuleBuilder.DefineEnum怎么用?C# ModuleBuilder.DefineEnum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.Emit.ModuleBuilder
的用法示例。
在下文中一共展示了ModuleBuilder.DefineEnum方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildEnum
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();
}
示例2: GenerateEnum
private static EnumBuilder GenerateEnum (ModuleBuilder modBuilder)
{
return modBuilder.DefineEnum (_enumNamespace + "."
+ _enumName, TypeAttributes.Public, _enumType);
}
示例3: CreateEnumType
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;
}
示例4: GenerateEnumeration
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();
}
示例5: CreateEnum
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();
}
示例6: CreateEnumType
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;
}
示例7: CreateRTEnumType
/// <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;
}