我正在尝试迭代枚举,并使用其每个值作为参数调用方法.必须有一个比我现在更好的方法来做到这一点:
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) { /* ... */ }
Run Code Online (Sandbox Code Playgroud)
将枚举名称作为字符串,然后将它们解析回枚举,感觉很可怕.