Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Example:

Condition:

IF A > B THEN

PRINT B

ELSE

PRINT A

This condition is written as a string in coloumn of the table in SQL.

I want to fetch this condition from the table and convert this condition to the C# Code as

If(A > B )

{

print B...........

}

else

{

print A...........

}

Where A and B are the Dynamic values passed in the C#.
Posted
Comments
ProEnggSoft 30-Mar-12 8:53am    
Please see my solution (1). I have modified it with a link to another article, which can handle string expressions also

1 solution

For this purpose the expression evaluator can be used.
This article may be helpful to you

math / function / boolean /string expression evaluator[^]

From the following paragraph of the above article

"Thus, I've developed a set of simple classes called ExpressionEval and FunctionEval. These evaluators handle numeric, string, boolean, and datetime datatypes, and they support all the unary and binary operators available in C#. They also support functions (through the utilization of FunctionEval class) and have the ability to add custom functions by attaching an event handler that fires when a function name is not found."

it can be seen that strings can be handled.
 
Share this answer
 
v2
Comments
fjdiewornncalwe 30-Mar-12 10:26am    
OP's answer moved to comment:
"hi,
My string may be contains the string expression like: "abc==abc" etc..so this will not be helpfull me.."

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900