jeudi 22 mai 2014

c# - création d'une fonction de boucle dans une liste de fonction pas à pas - Stack Overflow


Right now, here's what I have:


enter image description here


What it does is iterate through a list of pre-set functions, the list being configured by the user. It does this by looping through the DataGridList like so:


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);
}
}

And in my Actions class I have a


Dictionary<string, Action<String, String, String>>

Named 'actions', which contains the pre-set functions, like this one for gathering source code:


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");
};

Now, I'd like to add a few pre-set functions for loops, being loop with the method 'start', and loop with the method 'end', possibly a method 'break' if needed. But with the way it works, iterating through each function and executing it, how could I have a loop function? I though of making it so when a loop function is found, it sets a variable as the loop function's index and once it reaches the 'end' function it goes back to the index previously mentioned until set requirements are met, however a problem would arise with multiple loops being used as demonstrated here:


loopA
loopB
...
stopB //loopA would stop at stopB and not stopA as it was intented to do.
stopA

This problem is an enigma for me and it's killing me because it's a very big feature that's most definitely needed.



Right now, here's what I have:


enter image description here


What it does is iterate through a list of pre-set functions, the list being configured by the user. It does this by looping through the DataGridList like so:


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);
}
}

And in my Actions class I have a


Dictionary<string, Action<String, String, String>>

Named 'actions', which contains the pre-set functions, like this one for gathering source code:


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");
};

Now, I'd like to add a few pre-set functions for loops, being loop with the method 'start', and loop with the method 'end', possibly a method 'break' if needed. But with the way it works, iterating through each function and executing it, how could I have a loop function? I though of making it so when a loop function is found, it sets a variable as the loop function's index and once it reaches the 'end' function it goes back to the index previously mentioned until set requirements are met, however a problem would arise with multiple loops being used as demonstrated here:


loopA
loopB
...
stopB //loopA would stop at stopB and not stopA as it was intented to do.
stopA

This problem is an enigma for me and it's killing me because it's a very big feature that's most definitely needed.


0 commentaires:

Enregistrer un commentaire