VB.NET logical expression evaluator

Posted by Tim on Stack Overflow See other posts from Stack Overflow or by Tim
Published on 2010-05-21T13:05:33Z Indexed on 2010/05/21 13:10 UTC
Read the original article Hit count: 185

Filed under:
|
|
|
|

I need to test a logical expression held in a string to see if it evaluate to TRUE or FALSE.(the strig is built dynamically)
For example the resulting string may contain "'dog'<'cat' OR (1>4 AND 4<6)". There are no variables in the string, it will logically evaluate. It will only contain simple operators = > < >< >= <= and AND , OR and Open and Close Brackets, string constants and numbers. (converted to correct syntax && || etc.)

I currently acheive this by creating a jscipt function and compiling it into a .dll. I then reference the .dll in my VB.NET project.

   class ExpressionEvaluator  
    {  
 function Evaluate(Expression : String)  
 {  
  return eval(Expression);  
 }  
    }  

Is there a simpler method using built in .NET functions or Lamdba expressions.

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about lambda