private Type CreateEnum() { List<string> lists = new List<string>(); lists.Add("男"); lists.Add("女"); AppDomain app = AppDomain.CurrentDomain; AssemblyName aName = new AssemblyName("EnumAssemble"); AssemblyBuilder ab = app.DefineDynamicAssembly(aName, AssemblyBuilderAccess.Run); ModuleBuilder mb = ab.DefineDynamicModule("EnumModule"); EnumBuilder eb = mb.DefineEnum("Sexs", TypeAttributes.Public, typeof(System.Int32)); for (int i = 0; i < lists.Count; i++) { eb.DefineLiteral(lists[i], i); } return eb.CreateType(); }
时间: 2024-10-25 22:13:04