当前位置:网站首页>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
边栏推荐
- 主从复制系统设计
- 【混合编程jni 】第十一篇之JNA详情
- Do an online GIF synthesis service at no cost
- [fundamentals of image processing] GUI image curve adjustment system based on MATLAB [including Matlab source code 1923]
- Unity3d plug-in anyportrait 2D bone animation
- 中金证券经理的开户链接开户买股票安全吗?有谁知道啊
- Restfultoolkitx of idea utility plug-in -- restful interface debugging
- 【混合编程jni 】第七篇之JNI 的命令行们
- Leetcode (452) - detonate the balloon with the minimum number of arrows
- VB. Net class library (Advanced - 2 overload)
猜你喜欢

FPGA -vga display

Parsing complex JSON in fluent
![[machine learning] - Introduction to vernacular and explanation of terms](/img/4c/e18fe52a71444c2ca08167ead9f28f.jpg)
[machine learning] - Introduction to vernacular and explanation of terms

树莓派初步使用

The sharp sword of API management -- eolink

xshell的安装、xftp的安装
![[fundamentals of image processing] GUI image histogram equalization system based on MATLAB [including Matlab source code 1924]](/img/8a/f5847eef7318f3db54aa2d4405b06a.jpg)
[fundamentals of image processing] GUI image histogram equalization system based on MATLAB [including Matlab source code 1924]

Flashtext, a data cleaning tool, has directly increased the efficiency by dozens of times

VB. Net class library (advanced version - 1)

在线协作文档综合评测 :Notion、FlowUs、Wolai、飞书、语雀、微软 Office、谷歌文档、金山文档、腾讯文档、石墨文档、Dropbox Paper、坚果云文档、百度网盘在线文档
随机推荐
您的连接不是私密连接
分享三種在Excel錶格中自動求和的方法
运筹说 第66期|贝尔曼也有“演讲恐惧症”?
【图像处理基础】基于matlab GUI图像曲线调整系统【含Matlab源码 1923期】
[mixed programming JNI] Part 7: JNI command lines
Learun low code OA system construction platform
从位图到布隆过滤器,C#实现
From bitmap to bloom filter, C # implementation
用C#通过sql语句操作Sqlserver数据库教程
不同的子序列问题I
Leetcode (122) - the best time to buy and sell stocks II
Electronic Society C language level 1 31. Calculate line segment length
leetcode:6103. Delete the minimum score of the edge from the tree [DFS + connected component + value record of the subgraph]
C语言:简单计算器多次使用代码实现
【强基计划】数学与物理竞赛中的微积分部分视频
Operator介紹
通过两个stack来实现Queue
Introduction to operator
How to write test cases and a brief introduction to go unit test tool testify
微信小程序自动生成打卡海报