动态创建一个枚举 [英] Dynamically create an enum
本文介绍了动态创建一个枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下stucture的枚举:
I have an enum of the following stucture:
public enum DType
{
LMS = 0,
DNP = -9,
TSP = -2,
ONM = 5,
DLS =9,
NDS = 1
}
我使用此枚举来获取名称和值。
由于没有添加多种类型的要求,我需要阅读从XML文件的类型和值。有没有通过,我可以从XML文件动态创建枚举,这样我可以保持项目结构的任何方式。
I'm using this enum to get the names and the values. Since there is a requirement to add more types, I need to read the type and the values from an XML file. Is there any way by which I can create this enum dynamically from XML file so that I can retain the program structure.
推荐答案
也许如果你想生成<$ 而不是
Probably, you should consider using a Dictionary<string, int>
instead.
,你应该考虑使用词典<字符串,整数过夜。 C $ C>枚举
在编译时间动态,你可能要考虑的 T4 。
If you want to generate the enum
at compile-time dynamically, you might want to consider T4.
这篇关于动态创建一个枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文