我处理一个特殊的项目,必须将Predicates(或Expressions)转换为字符串并存储在数据库上并检索它并将其转换为Predicates并对其进行评估,因为我想在运行时更改它。请帮我修改ConvertStringToPredicate和ConvertStringToPredicate方法。
public class Program
{
static void Main(string[] args)
{
string predicateStr = GetPredicateFromDb(100);
Predicate<Account> predicate = ConvertStringToPredicate(predicateStr);
Account account = new Account();
var status = account.Evaluate(predicate);
//...
}
public static string GetPredicateFromDb(int id)
{
//Get Predicate String From Database
//...
}
public static Predicate<Account> ConvertStringToPredicate(string predicate)
{
//???
}
public static string ConvertStringToPredicate(Predicate<Account> predicate)
{
//???
}
}
public class Account
{
public decimal Balance { get; set; }
public bool Evaluate(Predicate<Account> matchingCriteria)
{
//Evaluate Predicate
//...
}
}