如何从枚举中获取成员名单? [英] How to get a list of member names from Enum?
问题描述
Designs\可应用于表的样式。
命名空间:Novacode
装配:DocX(在DocX.dll中)版本:1.0.0.10(1.0.0.10)
语法:
public enum TableDesign
会员名称
自定义
表正常
TableGrid
LightShading
LightShadingAccent1
....
< blockquote>
等等。我想得到这些TableDesign的列表,所以我可以在一个创建新表的方法中重用它,所有这些都是可能的,但是我真的不知道如何从该枚举中获取列表:
foreach(TableDesign中的var test){
createTable(documentWord,test);
}
我该怎么做?
解决方案发现自己:
//从卷枚举中获取成员名称列表,
//找出数值,并显示
foreach(Enum.GetNames(typeof(Volume))中的字符串卷)
{
Console.WriteLine(Volume Member:{0} \ Value:{1},
volume,(byte)Enum.Parse(typeof(Volume),volume));
}
对于我使用的具体情况:
foreach(Enum.GetNames(typeof(TableDesign)中的var test)){
testMethod(documentWord,test);
}
在testMethod我有:
tableTest.Design =(TableDesign)Enum.Parse(typeof(TableDesign),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?
解决方案Found answer myself:
// get a list of member names from Volume enum, // figure out the numeric value, and display foreach (string volume in Enum.GetNames(typeof(Volume))) { Console.WriteLine("Volume Member: {0}\n Value: {1}", volume, (byte)Enum.Parse(typeof(Volume), volume)); }
For my specific case I've used:
foreach (var test in Enum.GetNames(typeof(TableDesign))) { testMethod(documentWord, test); }
and in testMethod I've:
tableTest.Design = (TableDesign) Enum.Parse(typeof(TableDesign), test);
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 :-)
这篇关于如何从枚举中获取成员名单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!