当前位置:网站首页>Simple test lightweight expression calculator fly
Simple test lightweight expression calculator fly
2022-06-26 23:13:00 【gc_ two thousand two hundred and ninety-nine】
Flee yes GitHub Based on .net Lightweight mathematical expression parsing and calculator , It supports evaluating mathematical expressions 、 Mathematical expressions with variables 、 Mathematical expressions with special processing functions, etc . From the wechat official account, you can see about Flee The introduction of ( reference 1 It is a blog post of the same name from Baidu ), Prepare to test , Use this module to calculate mathematical expressions and mathematical expressions with variables .
Use VS2019 establish Winform Program , adopt NuGet Find and install Flee Packages and dependencies , As shown in the figure below :

Use Flee Calculating a mathematical expression without variables and special handling functions is simple , Just use the sample code given on its official website , The test code and running interface are shown in the following figure .
try
{
ExpressionContext context = new ExpressionContext();
IDynamicExpression calcResult = context.CompileDynamic(txtExpression.Text);
txtResult.Text =Convert.ToString(calcResult.Evaluate());
}
catch (ExpressionCompileException ex)
{
if (ex.Reason == CompileExceptionReason.SyntaxError)
{
txtResult.Text = "Check your expression syntax" + "\r\n" + ex.Message;
}
else
{
txtResult.Text = ex.Message;
}
}

Next, test the mathematical expression with variables , The most important thing is ExpressionContext class , This class is used to save variables in expressions , The test code and running interface are shown in the following figure .
try
{
ExpressionContext context = new ExpressionContext();
foreach(DataGridViewRow dgvr in dgvParams.Rows)
{
decimal tmpValue = 0;
if(string.IsNullOrEmpty(Convert.ToString(dgvr.Cells[0].Value))
|| !decimal.TryParse(Convert.ToString(dgvr.Cells[1].Value),out tmpValue))
{
continue;
}
context.Variables[Convert.ToString(dgvr.Cells[0].Value)] = tmpValue;
}
IDynamicExpression calcResult = context.CompileDynamic(txtExpression.Text);
txtResult.Text =Convert.ToString(calcResult.Evaluate());
}
catch (ExpressionCompileException ex)
{
if (ex.Reason == CompileExceptionReason.SyntaxError)
{
txtResult.Text = "Check your expression syntax" + "\r\n" + ex.Message;
}
else
{
txtResult.Text = ex.Message;
}
}

Flee It's more powerful , This article only tests the simplest of these uses , I will continue to learn in the future Flee Usage of .
reference :
[1]https://github.com/mparlak/Flee
[2]https://github.com/mparlak/Flee/wiki/Examples
边栏推荐
- [strong foundation program] video of calculus in mathematics and Physics Competition
- Weaving dream collection plug-ins are recommended to be free collection plug-ins
- 数据治理啥都干
- 【混合编程jni 】第十一篇之JNA详情
- 电子协会 C语言 1级 30 、 等差数列末项计算
- [interface] pyqt5 and swing transformer for face recognition
- 【混合编程jni 】第六篇之native 中字符串和数组的操作
- 简析攻防演练中蓝队的自查内容
- Tensorrt笔记(七)Tensorrt使用问题整理
- 【图像处理基础】基于matlab GUI图像曲线调整系统【含Matlab源码 1923期】
猜你喜欢

阿里云服务器的购买、基本配置、(xshell)远程连接、搭建环境

Learun low code OA system construction platform

【界面】pyqt5和Swin Transformer对人脸进行识别

Open world mecha games phantom Galaxy

【图像处理基础】基于matlab GUI图像直方图均衡化系统【含Matlab源码 1924期】

From bitmap to bloom filter, C # implementation

UnityEditor编辑器扩展-表格功能

VB. Net class library (Advanced - 2 overload)

WP collection plug-in tutorial no thanks for WordPress collection of rules

Unityeditor Editor Extension - table function
随机推荐
Yolov6: the fast and accurate target detection framework is open source
Leetcode (763) -- dividing letter ranges
Leetcode - the best time to buy or sell stocks
Selenium电脑上怎么下载-Selenium下载和安装图文教程[超详细]
Reading graph augmentations to learn graph representations (lg2ar)
【图像处理基础】基于matlab GUI图像曲线调整系统【含Matlab源码 1923期】
通过两个stack来实现Queue
Unity animation knowledge of Art
您的连接不是私密连接
Unity3D插件 AnyPortrait 2D骨骼动画制作
【混合编程jni 】第九篇之Jni总结
Operator介绍
【混合编程jni 】第十二篇 jnaerator
DLA model (classification model + improved segmentation model) + deformable convolution
买股票通过中金证券经理的开户二维码开户资金是否安全?想开户炒股
WP collection plug-in tutorial no thanks for WordPress collection of rules
Learun low code OA system construction platform
[fundamentals of image processing] GUI image curve adjustment system based on MATLAB [including Matlab source code 1923]
CVPR 2022 - Interpretation of selected papers of meituan technical team
Share three methods of automatic summation in Excel