【发布时间】:2011-02-07 15:10:18
【问题描述】:
我试图遍历一个枚举,并使用它的每个值作为参数调用一个方法。必须有比我现在更好的方法来做到这一点:
foreach (string gameObjectType in Enum.GetNames(typeof(GameObjectType)))
{
GameObjectType kind = (GameObjectType) Enum.Parse(typeof (GameObjectType), gameObjectType);
IDictionary<string, string> gameObjectData = PersistentUtils.LoadGameObject(kind, persistentState);
}
//...
public static IDictionary<string, string> LoadGameObject(GameObjectType gameObjectType, IPersistentState persistentState) { /* ... */ }
将枚举名称作为字符串,然后将它们解析回枚举,感觉很可怕。
【问题讨论】: