Verify string with comparison/logic operators


(Without using test suite)

Is it possible to verify string expression passing as an input?

The issue is making this dynamic, gathering expression from file and x from app

input expression (string) e.g. “x>5 and x<=8”
input parameter x (string)
result (boolean)

we would modell as
CInt(x) > 5 and CInt(x) <= 8

A fully functionality like an EVAL() (javascript) we dont have Out-Of-The-Box

But lets loop in @StefanSchnell as maybe we can integrate an inline compilation / execution e.g. with Roslyn and build a EVAL feature by ourself

1 Like

Thanks for info Peter. It would be useful while getting an expression from an input source file. It looks like right now I can only hardcode it


Hello Vinncent,
here an approach how you can handle your requirement via an Invoke Code activity.
Best regards

//-Input Arguments------------------------------------------------------
string condition = "x > 5 && x <= 8";
string variable = "7";

//-Output Arguments-----------------------------------------------------
bool Result;

//-UiPath Invoke Code Activity Begin------------------------------------

string Code = @"
using System;
class Eval {{
  public bool CheckCondition() {{
    int x = {1};
    if({0}) {{
      return true;
    return false;

//-Set condition to {0} and variable to {1}-----------------------------
string code = string.Format(Code, condition, variable);

CodeDomProvider CodeProvider = new CSharpCodeProvider();
CompilerResults CompResult = CodeProvider.CompileAssemblyFromSource(new CompilerParameters(), code);
object oInstance = CompResult.CompiledAssembly.CreateInstance("Eval", false, BindingFlags.Instance | BindingFlags.Public | BindingFlags.CreateInstance, null, null, null, null);
MethodInfo MethInfo = oInstance.GetType().GetMethod("CheckCondition");
object oResult = MethInfo.Invoke(oInstance, null);
Result = Convert.ToBoolean(oResult);

//-UiPath Invoke Code Activity End--------------------------------------

Thank you for your engage. In the meantime I found a package from source named “C# Eval Expression | Eval Function” which uses same approach.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.