Run IfValue comparsion based on the length of an array in ParameterDic.

IScriptCommand arrayCommand =   
  ScriptCommands.IfArrayLength(ComparsionOperator.GreaterThan, "{Variable1}", 5,  
    ScriptCommands.PrintDebug("Array length is Greater than 5"),
	ScriptCommands.PrintDebug("Array length is not greater than 5"));	
	
await ScriptRunner.RunScriptAsync(new ParameterDic() { 
                { "Variable1", (new[] {1, 2, 3, 4, 5, 6 }) }				
            }, arrayCommand);	

Result:
Array length is Greater than 5

Implementation:
public static IScriptCommand IfArrayLength(ComparsionOperator op, string arrayVariable = "{array}", 
    string valueVariable = "{value}",
    IScriptCommand trueCommand = null, IScriptCommand otherwiseCommand = null)
{
    return ScriptCommands.AssignValueConverter(ValueConverterType.GetProperty, "{GetPropertyConverter}", 
        ScriptCommands.Reassign(arrayVariable, "{GetPropertyConverter}", "{ArrayLength}", false, 
            ScriptCommands.PrintLogger(MetroLog.LogLevel.Debug, "Length of array is {ArrayLength}",  
            ScriptCommands.IfValue(op, "{ArrayLength}", valueVariable, trueCommand, otherwiseCommand))), "Length");
}

Last edited Jul 25, 2014 at 2:49 PM by lycj, version 2

Comments

No comments yet.