我在C#程序中设置了一个动态脚本(使用CSScriptLibrary),如下所示:
string sqlReturnValue= cmd.ExecuteQuery();;
dynamic script = CSScript.Evaluator
.LoadCode(@"using System;
public class Script
{
string GetValue()
{
return " + sqlReturnValue + @";
}
}");
output = script.GetValue();
sqlReturnValue是一个字符串,我从类似于此的SQL查询中返回:
"Salaried Grade 1".Substring(0, 7) == "Salaried") ? "CLA_SH_S" : "CLA_SH_H";
当我尝试执行此操作时,动态代码会给我"Unexpected symbol )', expecting ;'"
& "Unexpected symbol :', expecting ;'"
如何编写此动态脚本以便正确评估三元组?
答案 0 :(得分:1)
如果有人发现这个有用,我可以按照以下方式工作:
string sqlReturnValue = cmd.ExecuteQuery();
// Use CSScript to evaluate the test string returned from the SQL Query
var Product = CSScript.Evaluator
.CreateDelegate(@"string Product()
{
return " + sqlReturnValue + @";
}");
output = (string)Product();