首页
/ Jace.NET 技术文档

Jace.NET 技术文档

2024-12-28 07:00:39作者:侯霆垣

1. 安装指南

Jace.NET 是一个为 .NET 平台设计的高性能计算引擎。以下是安装 Jace.NET 的步骤:

  1. 下载源码:从 GitHub 下载 Jace.NET 的源代码。
  2. 构建项目:使用 Visual Studio 打开下载的源代码,然后构建项目以生成 DLL 文件。
  3. 引用 DLL:在你的项目中添加对生成的 Jace.NET DLL 的引用。

2. 项目的使用说明

Jace.NET 支持将字符串形式的数学公式动态解析并执行。以下是一些使用 Jace.NET 的基本方法:

直接执行给定数学公式

使用提供的变量直接执行一个给定的数学公式:

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2.5);
variables.Add("var2", 3.4);

CalculationEngine engine = new CalculationEngine();
double result = engine.Calculate("var1*var2", variables);

构建一个接受字典输入的.NET Func

构建一个接受包含每个变量值的字典的 .NET Func:

CalculationEngine engine = new CalculationEngine();
Func<Dictionary<string, double>, double> formula = engine.Build("var1+2/(3*otherVariable)");

Dictionary<string, double> variables = new Dictionary<string, double>();
variables.Add("var1", 2);
variables.Add("otherVariable", 4.2);

double result = formula(variables);

构建一个强类型.NET Func

构建一个强类型的 .NET Func:

CalculationEngine engine = new CalculationEngine();
Func<int, double, double> formula = (Func<int, double, double>)engine.Formula("var1+2/(3*otherVariable)")
    .Parameter("var1", DataType.Integer)
    .Parameter("otherVariable", DataType.FloatingPoint)
    .Result(DataType.FloatingPoint)
    .Build();

double result = formula(2, 4.2);

3. 项目API使用文档

以下是 Jace.NET 的一些关键 API:

  • CalculationEngine.Calculate(string formula, Dictionary<string, double> variables): 直接执行一个给定的数学公式。
  • CalculationEngine.Build(string formula): 构建一个可以接受字典输入的 Func。
  • CalculationEngine.Formula(string formula): 用于构建强类型 Func 的方法。

4. 项目安装方式

如前所述,以下是安装 Jace.NET 的步骤:

  1. 从 GitHub 下载 Jace.NET 的源代码。
  2. 使用 Visual Studio 打开并构建项目。
  3. 在你的项目中添加对生成的 DLL 的引用。

通过以上步骤,你就可以在项目中使用 Jace.NET 进行数学公式的动态解析和执行了。

登录后查看全文
热门项目推荐