现在,这就是我所拥有的:
它的作用是遍历预设功能列表,该列表由用户配置。它通过循环遍历DataGridList来实现这一点:
foreach (DataGridRow row in configTable.Items)
{
ConfigRow crow = (ConfigRow)row.Item; //ConfigRow is just a generic class for the row values
string val1 = crow.colValue;
string val2 = crow.colValue2;
//...Some other, irrelevant code for parsing user-set variables in the values...
if (actions.actions.ContainsKey(crow.colType))
{
((Action<String, String, String>)actions.actions[crow.colType]).Invoke(crow.colMethod, val1, val2);
}
}
在我的Actions类中,我有一个
Dictionary<string, Action<String, String, String>>
命名&#39; actions&#39;,其中包含预设功能,就像收集源代码一样:
actions["Get source"] = (Action<String, String, String>)delegate(String method, String val1, String val2)
{
using (WebClient wb = new WebClient())
{
if (method == "POST")
{
wb.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
variable = wb.UploadString(val1, val2);
}
else
{
variable = wb.DownloadString(val1);
}
}
window.appendConsole("Retrieved contents of '" + val1 + "' using " + method + " method");
};
现在,我想为循环添加一些预设功能,使用方法&#39; start&#39;循环,然后循环使用方法&#39; end&#39;,可能是一种方法&#39;打破&#39;如果需要的话。但是通过它的工作方式,遍历每个函数并执行它,我怎么能有一个循环函数?我找到一个循环函数时就这样做了,它设置一个变量作为循环函数的索引,一旦它到达“结束”。函数它返回到前面提到的索引,直到满足设置要求,但是如下所示使用多个循环会出现问题:
loopA
loopB
...
stopB //loopA would stop at stopB and not stopA as it was intented to do.
stopA
这个问题对我来说是一个谜,它杀了我,因为它是一个非常需要的非常大的功能。