User defined formulas in C#

2019-04-13 09:31发布

I have an application where for each object the user can specify his own measurepoints. The values of theese measurements will then be used to classify the object as i e A - needs service, B - service should be scheduled within X days, C - no service needed ATM

However theese objects can be almost anything and there is no way we can hard code how the measured values should be aggregated to a classification, we need to leave that to the user.

Have you any suggestions on how we can provide a way for the user to enter his own formulas for this? It does not have to be idiot-proof, we dont have that many customers so we can assist them as long as they can explain it to us.

标签: c# eval
7条回答
该账号已被封号
2楼-- · 2019-04-13 09:58

You should use .NET 3.5 Expressions, in System.Linq.Expressions. Scott Gu has provided a Dynamic Expression API that allows you to evaluate strings to turn them into expression trees, which may then be evaluated by code either to examine the expression contents, or compiled for execution.

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

查看更多
登录 后发表回答