如何从 Enum 中获取成员名称列表?
这应该是一个相当简单的问题。我正在使用 DocX 库创建新的 Word 文档。我想制作一个测试Word文档,看看每个TableDesign(枚举)是什么样子,以选择我需要的一个。
可应用于表格的设计\样式。 命名空间:Novacode 程序集:DocX(在 DocX.dll 中)版本:1.0.0.10 (1.0.0.10)
语法:
公共枚举TableDesign
会员姓名
定制
表法线
表格网格
光照
LightShadingAccent1
....
等等。我想获得这些 TableDesign 的列表,以便我可以在使用新设计创建新表的方法中重用它以实现所有可能性,但我真的不知道如何从该枚举中获取列表:
foreach (var test in TableDesign) {
createTable(documentWord, test);
}
我如何获得它?
This should be fairly simple question. I'm using DocX library to create new word documents. I wanted to make a test word document to see how each TableDesign (enum) looks like to choose the one I need.
Designs\Styles that can be applied to a table.
Namespace: Novacode
Assembly: DocX (in DocX.dll) Version: 1.0.0.10 (1.0.0.10)Syntax:
public enum TableDesign
Member name
Custom
TableNormal
TableGrid
LightShading
LightShadingAccent1
....
And so on. I would like to get a list of those TableDesign's so i could reuse it in a method creating new table with new design for all possibilities, but I don't really know how to get the list from that enum:
foreach (var test in TableDesign) {
createTable(documentWord, test);
}
How do I get that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我自己找到了答案:
对于我使用的具体情况:
并且在 testMethod 中我:
它工作没有问题(即使很慢,但我只是想快速得到东西(并且一次性性能并不重要)也许
它也会对将来的人有所帮助:-)
Found answer myself:
For my specific case I've used:
and in testMethod I've:
It worked without a problem (even if it was slow, but I just wanted to get things quickly (and being onetimer performance didn't matter).
Maybe it will help someone in future too :-)
或者:
GetValue
将以enum
的形式返回值的Volume[]
。打印enum
值将调用其ToString()
,并按其名称进行渲染。转换为int
(优于byte
)将给出其编号。Alternately:
GetValue
will return anVolume[]
of the values asenum
s. Printing anenum
value will call itsToString()
, rendering it by it name. Casting toint
(better thanbyte
) will give its number.我想对 MadBoy 的答案添加评论,不知道为什么我不能...
无论如何,就像他说的那样,这就是要走的路,
我也认为测试可能看起来
更自然
最后,关于性能问题,我认为枚举往往很小,所以我根本不用担心
I wanted to add a comment on MadBoy's answer, dont know why i cant...
anyway like he said thats the way to go
also i think the testing could be like
it just seems more natural
last, about the performance issue, i think enums tend to be very small so i wont be worried at all