NTDLS.ExpressionParser 1.1.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package NTDLS.ExpressionParser --version 1.1.3                
NuGet\Install-Package NTDLS.ExpressionParser -Version 1.1.3                
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="NTDLS.ExpressionParser" Version="1.1.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NTDLS.ExpressionParser --version 1.1.3                
#r "nuget: NTDLS.ExpressionParser, 1.1.3"                
#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 NTDLS.ExpressionParser as a Cake Addin
#addin nuget:?package=NTDLS.ExpressionParser&version=1.1.3

// Install NTDLS.ExpressionParser as a Cake Tool
#tool nuget:?package=NTDLS.ExpressionParser&version=1.1.3                

NTDLS.ExpressionParser

📦 Be sure to check out the NuGet package: https://www.nuget.org/packages/NTDLS.ExpressionParser

ExpressionParser is a mathematics parsing engine for .net. It supports expression nesting, custom variables, custom functions all standard mathematical operations for integer, decimal (floating point), logic and bitwise.

It addition to the custom functions and variables, these are built in: ACOS, ASIN, ATAN, ATAN2, LDEXP, SINH, COSH, TANH, LOG, LOG10, EXP, MODPOW, SQRT, POW, FLOOR, CEIL, NOT, AVG, SUM, TAN, ATAN, SIN, COS, ABS.

If you can for the C++ version you can find it at: https://github.com/NTDLS/CMathParser

Basic example usage:

Be sure to check out the NuGet package: https://www.nuget.org/packages/NTDLS.ExpressionParser/

Simple Example:

In this example we simply call the static function Expression.Evaluate to compute the string expression.


var result = Expression.Evaluate("10 * ((1000 / 5 + (10 * 11)))");
Console.WriteLine($"{result:n2}");

Simple Example (with work):

In this example we simply call the static function Expression.Evaluate to compute the string expression, and we also supply an output parameter for which the parser will use to explain the operations.


var result = Expression.Evaluate("10 * ((1000 / 5 + (10 * 11))), out var explination");

Console.WriteLine($"{result:n2}");
Console.WriteLine(explination);

Advanced Example:

In this example we will create an expression that uses two built in functions "Ceil" and "Sum", a custom function called "DoStuff" and one variable called "extra".


var expression = new Expression("10 * ((5 + extra + DoStuff(11,55) + ( 10 + !0 )) * Ceil(SUM(11.6, 12.5, 14.7, 11.11)) + 60.5) * 10");

//Add a value for the variable called "extra".
expression.AddParameter("extra", 1000);

//Handler for the custom function:
expression.AddFunction("DoStuff", (double[] parameters) =>
{
    double sum = 0;
    foreach (var parameter in parameters)
    {
        sum += parameter;
    }
	return sum;
});

var result = ExpressionParser.Evaluate(expression);

Console.WriteLine($"{result:n2}");

License

MIT

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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 is compatible.  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 is compatible.  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.
  • net6.0

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.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.4 101 10/3/2024
1.1.3 80 10/3/2024
1.1.2 253 11/15/2023
1.1.1 149 10/17/2023
1.1.0 134 10/16/2023
1.0.0 154 10/13/2023

net8