当前位置:网站首页>The dynamic analysis and calculation of expressions are really delicious for flee
The dynamic analysis and calculation of expressions are really delicious for flee
2022-07-03 06:29:00 【xuhss_ com】
High quality resource sharing
| Learning route guidance ( Click unlock ) | Knowledge orientation | Crowd positioning |
|---|---|---|
| 🧡 Python Actual wechat ordering applet 🧡 | Progressive class | This course is python flask+ Perfect combination of wechat applet , From the deployment of Tencent to the launch of the project , Create a full stack ordering system . |
| Python Quantitative trading practice | beginner | Take you hand in hand to create an easy to expand 、 More secure 、 More efficient quantitative trading system |
Preface
In many projects, there are often scenarios that require dynamic parsing of expressions and calculations , For example, some automatic approval rules , Or the values of some variables are dynamically calculated during operation through the maintained formula ; Due to scenario requirements , You need to configure the corresponding expression flexibly , Then I hope to calculate the corresponding value according to the maintained expression when necessary ; When I was chatting with my colleagues, I said Flee, I think it works very well , Hurry to share a wave with your friends .
Text
1. Flee brief introduction
Flee Is a . net Framework's expression parser and evaluator , You can evaluate string expressions at run time ( Such as :sqrt(a^2 + b^2), among a、b It's a variable. ). Its parsing and computing speed is relatively fast and efficient .
Flee Support Net6.0、Net5.0、Netstandard2.1、Netstandard2.0.
Not much else , Let's go directly to a few examples to experience a wave , For more details, you can go to github Look up :
github Address :https://github.com/mparlak/Flee
2. Case presentation
The case is demonstrated through the console , On the installation Flee Bag can .

2.1 Super simple case
There are specific comments in the code , I won't go into details here , The screenshot is as follows :

The content of this simple expression has been determined , All are computable , No variables .
Application scenarios 1: Expression fixed , A scene calculated directly by splicing the corresponding values .
Application scenarios 2: The expression is not fixed , However, some variable values are marked with special characters during formula maintenance , Then find the marked variable in the form of regular expression , And replace with the corresponding business field value .
Such as :[a]+[b]+3.14, In this case, the variables marked with brackets can be found through regular expressions , Then we can calculate by replacing the corresponding value with the name of the corresponding intermediate variable .
2.2 Expressions with variables
There are specific comments in the code , I won't go into details here , The screenshot is as follows :

This form with variables is relatively flexible , It can be configured at will , Just attach values to the corresponding variables during calculation . There may be some questions from my friends , How to adjust variable uncertainty , In fact, in the actual application scenario , You should know the variables that need to be passed in many times , Just dynamically transfer values according to the rules of the formula .
Application scenarios : It is different from the simple case , No special tag variables are required , Here, you can directly maintain the formula and transfer values normally . This situation is relatively flexible , Corresponding formulas can be configured for related businesses , The last pass is the corresponding variable for calculation , Finally, relevant business processing can be carried out according to the calculated value .
2.3 Expression combination
CalculationEngine You can combine expressions , The calculation engine will use the results of other expressions inside the engine 、 Dependency relationship , Then calculate the combined results in sequence .

Application scenarios : This is generally used in scenarios with multiple expressions , Is similar to the Excel The same expression in multiple cells in , Every cell has an expression , Then one cell will reference the value calculated by the expression in other cells , Finally, the result .
2.4 spread function
Sometimes computing logic is encapsulated in a project , Just pass in the required value , There is no need for each caller to rewrite the relevant calculation logic ,Flee It also supports the combination of custom functions in expressions , The demonstration is as follows :
First, write the relevant methods in a class **, The method here must be static 、 Public **, as follows :

Then you can use it in the expression , as follows :

2.5 Functions that support variable arguments
It is used in the same way as above , Customize a method , Only the parameters of this method are uncertain , Variable , as follows :

Use... In expressions :

2.6 The return value is Boolean Expression of type
In practical application scenarios , Sometimes you just need to get a yes no result , It may not be necessary to calculate a specific value ;

Application scenarios : This situation is generally used for the requirements of some automatic decision rules , For example, the results of some reports have a range of values for different business types , If it is out of range, it means non-compliance , If you rely on human judgment, it may not be so efficient ; Similar to this case of comparative data , If it is only a simple comparison, it is easy to realize , If it is a more complicated relationship comparison , This method is relatively flexible .
Okay , For the time being, let's talk about how to use it , The pictures in this article already contain all the codes . I will also submit the code later github And code cloud .
summary
The above is just a few simple examples , Specific partners can use it according to business scenarios . If you have a better tool library , Comments are welcome , Learning together .
Focus on “Code Variety industry ”, Study with me .
边栏推荐
- . Net program configuration file operation (INI, CFG, config)
- [open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle
- Introduction to software engineering
- Shell conditional statement
- Zhiniu stock project -- 04
- Get a screenshot of a uiscrollview, including off screen parts
- Chapter 8. MapReduce production experience
- Zhiniu stock project -- 05
- 代码管理工具
- Svn branch management
猜你喜欢

Create your own deep learning environment with CONDA

Yolov3 learning notes

Merge and migrate data from small data volume, sub database and sub table Mysql to tidb
![[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle](/img/f8/0e3fbfd13bf06291a73200552ff17a.png)
[open source project recommendation colugomum] this group of undergraduates open source retail industry solutions based on the domestic deep learning framework paddlepadddle

scroll-view指定滚动元素的起始位置

Click cesium to obtain three-dimensional coordinates (longitude, latitude and elevation)

有意思的鼠標指針交互探究

Yolov1 learning notes

轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷

Creating postgre enterprise database by ArcGIS
随机推荐
ODL framework project construction trial -demo
MATLAB如何修改默认设置
Shell conditional statement
Jackson: what if there is a lack of property- Jackson: What happens if a property is missing?
【无标题】5 自用历程
Print time Hahahahahaha
[system design] proximity service
Code management tools
【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF
YOLOV1学习笔记
Use abp Zero builds a third-party login module (I): Principles
POI dealing with Excel learning
Cesium entity (entities) entity deletion method
MySQL带二进制的库表导出导入
Creating postgre enterprise database by ArcGIS
SSH link remote server and local display of remote graphical interface
[untitled] 5 self use history
Kubesphere - build Nacos cluster
opencv鼠标键盘事件
Zhiniu stock -- 03