使用C#解析并执行公式 [英] Parse and execute formulas with C#

查看:107
本文介绍了使用C#解析并执行公式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个开源库来解析和执行C#中的公式/函数.

I am looking for an open source library to parse and execute formula/functions in C#.

我想创建一堆从接口(即IFormulaEntity)派生的对象,该对象具有属性/方法/值,并允许用户为这些对象指定公式.

I would like to create a bunch of objects that derive from an interface (i.e. IFormulaEntity) which would have properties/methods/values and the allow a user to specify formulas for those objects.

例如,我可能有

public class Employee : IForumulaEntity
{ 
      public double Salary { get; set; }
      public void SendMessage(string message)
}

然后允许应用程序用户编写类似的内容;

Then allow an application user to write something like;

Employee person = <get from datasource>
if (person.Salary > 1000)
    person.Salary += 1000;

person.SendMessage("Hello");

这看起来像C#",但是它将是一种简化的编程语言.我知道有很多要问的.我希望我的用户具备一定的能力(即可以编写自己的Excel公式).

This "looks like C#" but it would be a simplified programming language. I know it's alot to ask. I would expect my users to be reasonably capable (i.e. can write their own Excel formulas).

推荐答案

查看Windows Workflow Foundation中的规则引擎功能.

Look into the Rules Engine functionality that is part of Windows Workflow Foundation.

这不是一个人们想看的地方.但是,作为工作的一部分,他们确实制作了一个允许Workflow开发人员使用可配置规则和表达式的UI,即使您没有使用Workflow,他们也想出了一种在自己的应用程序中执行相同操作的方法.完全没有.他们的文档包括在Windows Forms应用程序中托管此功能的示例.

This is not a place one would think to look. However, as part of the work they did to produce a UI that allows a Workflow developer to use configurable rules and expressions, they've come up with a way to do the same thing in your own application, even if you are not using Workflow at all. Their documentation includes examples of hosting this functionality in a Windows Forms application.

这篇关于使用C#解析并执行公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆