-
Notifications
You must be signed in to change notification settings - Fork 1
Select
jdubs edited this page Oct 21, 2016
·
1 revision
Performs a traditional select or switch statement and returns the evaluated value.
SpecName (constant) The variable for assignment of the evaluated value.
Case (multiple) The object of comparison for the CaseArray parameter.
CaseArray (multiple) The key value pairs for comparison. Syntax is: {key=value}
ErrorMessage (multiple | optional) The error message to return when any error occurs.
This method programmatically mimics a select or switch statement. Essentially it replaces a long if statement. The method loops through the CaseArray attempting to find the matching key, and when found assigns the value to the SpecName variable. For example a Case of "P" and a CaseArray of {C=Catcher}{P=Pitcher}{LF=Outfield} will return "Pitcher".
public static void Select(string SpecName, object Case, object CaseArray, object ErrorMessage)
{
Break();
try
{
string result = (string)ErrorMessage;
foreach (String m in SelectCaseMatches(CaseArray))
{
string[] keypair = m.Split(new string[] { "=" }, StringSplitOptions.None);
if (keypair[0] == (string)Case)
{
result = keypair[1];
}
}
Variable(SpecName).Value = result;
}
catch (Exception ex)
{
throw new Four51ActionsException(ex.Message, (string)ErrorMessage);
}
}