KevinComponent.CalculationEngine
1.0.0.3
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
.NET Framework 4.8
This package targets .NET Framework 4.8. The package is compatible with this framework or higher.
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 KevinComponent.CalculationEngine --version 1.0.0.3
NuGet\Install-Package KevinComponent.CalculationEngine -Version 1.0.0.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="KevinComponent.CalculationEngine" Version="1.0.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add KevinComponent.CalculationEngine --version 1.0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: KevinComponent.CalculationEngine, 1.0.0.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 KevinComponent.CalculationEngine as a Cake Addin #addin nuget:?package=KevinComponent.CalculationEngine&version=1.0.0.3 // Install KevinComponent.CalculationEngine as a Cake Tool #tool nuget:?package=KevinComponent.CalculationEngine&version=1.0.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
CaculationEngine
CalculationEngine is a useful tool for calculating complex formulas. <br> It's inspired by Jace.NET, and some code was taken from Jace.NET.
Simple Code
- Here is a simple piece of code that demonstrates what a CalculationEngine is.
// Define CalculationEngine var engine = new CalculationEngine(); // Calculate Formulas var answer = engine.Calculate("1 + 3"); var answer2 = engine.Calculate("3 + 5 * 9"); var answer3 = engine.Calculate("pow(3, 2) + (2 - 3)"); /****************** RESULT ******************/ // answer : 4 // answer2 : 48 // answer3 : 8
Features
The CalculationEngine can calculate formulas that contain strings and objects.
- Calculating String Constants And Variables
var engine = new CalculationEngine(); var variables = new Dictionary<string, object>() { { "code", "PRESENT" } }; var answer = engine.Calculate("if(CODE == \"PRESENT\", \"TRUE\", \"FALSE\")", variables); /****************** RESULT ******************/ // answer : "TRUE"
<br>
The CalculationEngine can access the object properties by PropertyConnector
- Point Class for formula
public class Point { public Point(string name, double x, double y) { Name = name; X = x; Y = y; } public string Name { get; set; } public double X { get; set; } public double Y { get; set; } }
- Implementing a PropertyConnector to access Point class properties
public class PointPropertyConnector : PropertyConnector { public PointPropertyConnector(bool caseSensitive) : base(caseSensitive) { } protected override object? OnGetPropertyValue(object target, string propertyName) { if (target is Point point) { if (propertyName.Equals(ConvertPropertyName(".Name"))) return point.Name; else if (propertyName.Equals(ConvertPropertyName(".X"))) return point.X; else if (propertyName.Equals(ConvertPropertyName(".Y"))) return point.Y; } return null; } }
- Calculate formulas with the Point class
var engine = new CalculationEngine(new CalculationEngineOptions() { PropertyConnectorFactory = caseSensitive => new PointPropertyConnector(caseSensitive) }); var variables = new Dictionary<string, object>() { { "p1", new Point("A", 0, 1) }, { "p2", new Point("B", 1.25, -2.56) }, { "Code", "A" } }; var answer = engine.Calculate("p1.x + p2.y", variables); var answer2 = engine.Calculate("if ( Code == p1.Name, \"True\", \"False\")", variables); /****************** RESULT ******************/ // answer : -2.56 // answer2 : "True"
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. 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 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. |
.NET Core | netcoreapp3.1 is compatible. |
.NET Framework | net48 is compatible. net481 was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- No dependencies.
-
.NETFramework 4.8
- 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.
.net 8.0, .net48, .netcoreapp3.1 supported.