c# - Converting Expression<T, bool> to String -


i need way recreate dynamically generated reports @ point in future. long story short, need store specific linq query (different each report) database , execute query dynamic linq later on.

this good, can't find way convert expression string.

as in:

expression<func<product, bool>> exp = (x) => (x.id > 5 && x.warranty != false); 

should become:

"product.id > 5 && product.warranty != false" 

is there way that?

this may not best/most efficient method, does work.

expression<func<product, bool>> exp = (x) => (x.id > 5 && x.warranty != false);  string expbody = ((lambdaexpression)exp).body.tostring();  // gives: ((x.id > 5) andalso (x.warranty != false))  var paramname = exp.parameters[0].name; var paramtypename = exp.parameters[0].type.name;  // add "orelse" , others... expbody = expbody.replace(paramname + ".", paramtypename + ".")                  .replace("andalso", "&&");   console.writeline(expbody); // output: ((product.id > 5) && (product.warranty != false)) 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -