MathExpression.net
1.0.2.5005
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package MathExpression.net --version 1.0.2.5005
NuGet\Install-Package MathExpression.net -Version 1.0.2.5005
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MathExpression.net" Version="1.0.2.5005" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MathExpression.net --version 1.0.2.5005
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: MathExpression.net, 1.0.2.5005"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MathExpression.net as a Cake Addin #addin nuget:?package=MathExpression.net&version=1.0.2.5005 // Install MathExpression.net as a Cake Tool #tool nuget:?package=MathExpression.net&version=1.0.2.5005
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
MathExpression.net
A simple .NET 5 Math Expression Parser / Interpreter.
This library interprets mathematical expressions from text input.
Important Note on Localization
Currently the Lib expects German localized input Strings (e.g. for Numbers: Use 2,5 instead 2.5 and Dates in Format dd.mm.yyy ) Will be corrected/extended in one of the next versions
Basic functions
- Math Operations [+] [-] [\] [*] [^]
- String, Date, Number Comparsion [<] [<=] [>] [>=] [=]
- Date calculations (Range)
- Extract Date parts (month, day, year)
- Conditional statement IF THEN ELSE
Installation
MathExpression.net on nuget.org
Examples
Simple Math
var result = ExpressionEvaluator.EvaluateExpression("1+1");
____________________________________
// result.number -> 2;
// result.ToString() -> "2"
More Math
var result = ExpressionEvaluator.EvaluateExpression("((1 + 1) * 10 / (7 / 3.5)) ^ 2 / 10000");
____________________________________
// result.number -> 1;
// result.ToString() -> "1"
If Then Else
var result = ExpressionEvaluator.EvaluateExpression($"IF 1 > 0 THEN 'Yes, it´s true!' ELSE 'No! Your wrong ..'");
____________________________________
// result.ToString() -> "Yes, it´s true!");
If Then Else (AND/OR)
var result = ExpressionEvaluator.EvaluateExpression($"IF (1 > 0 AND 'Yes' != 'No') OR 100/10=10 THEN 'Yes, it´s true!' ELSE 'No! Your wrong ..'");
____________________________________
// result.ToString() -> "Yes, it´s true!");
String Comparsion
var result = ExpressionEvaluator.EvaluateExpression("'MyString' = 'MyString'");
____________________________________
// result.boolean == True;
Date Calculation
var d1 = new DateTime(2020, 01, 01);
var d2 = new DateTime(2019, 01, 01);
var result = ExpressionEvaluator.EvaluateExpression($"{d1} - {d2}");
____________________________________
// result.dateRange.TotalDays -> 365
var d1 = new DateTime(2020, 01, 01);
var d2 = new DateTime(2019, 01, 01);
var result = ExpressionEvaluator.EvaluateExpression($"days({d1} - {d2})");
____________________________________
// result.number -> 365;
Date with strings Calculation
var d1 = "01.01.2020";
var d2 = "01.01.2019";
var result = ExpressionEvaluator.EvaluateExpression($"{d1} - {d2}");
____________________________________
// result.dateRange.TotalDays -> 365
Date Parts
var d1 = new DateTime(2021, 01, 01);
var result = ExpressionEvaluator.EvaluateExpression($"Year({d1})");
____________________________________
// result.ToString() -> "2021";
Between Date
var d1 = "01.01.2020";
var d2 = "31.12.2020";
var d3 = "15.06.2020";
var result = ExpressionEvaluator.EvaluateExpression($"{d3} BETWEEN {d1} AND {d2}");
____________________________________
// result.boolean -> True;
Between Numbers
var d1 = 1;
var d2 = 10;
var d3 = 5;
var result = ExpressionEvaluator.EvaluateExpression($"{d3} BETWEEN {d1} AND {d2}");
____________________________________
// result.boolean -> True;
Using Variables
var values = new Dictionary<string, object>
{
{ "FirstVar", 1.75 },
{ "SecondVar", 2 },
{ "ResultText", "Your Right!" }
};
var result = ExpressionEvaluator.EvaluateExpression($"IF FirstVar < SecondVar THEN ResultText", values);
____________________________________
// result.ToString() -> "Your Right!"
Special Remarks
Special Shout-Out to Christian Parpart as initial Author - a long Time ago!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net5.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.0.2006 | 2,464 | 10/27/2021 |
1.1.0.2005 | 5,864 | 10/27/2021 |
1.0.2.5006 | 298 | 10/24/2021 |
1.0.2.5005 | 309 | 10/24/2021 |
1.0.1.2447 | 363 | 10/24/2021 |
1.0.1.2439 | 356 | 10/24/2021 |
1.0.1.1876 | 292 | 10/23/2021 |
1.0.1.1062 | 288 | 10/23/2021 |
1.0.1.504 | 299 | 10/24/2021 |
1.0.1.503 | 295 | 10/24/2021 |
1.0.1.70 | 346 | 10/24/2021 |
1.0.1.25 | 350 | 10/24/2021 |
1.0.0 | 317 | 10/23/2021 |