LfrlAnvil.Computable.Expressions 0.4.0

dotnet add package LfrlAnvil.Computable.Expressions --version 0.4.0
                    
NuGet\Install-Package LfrlAnvil.Computable.Expressions -Version 0.4.0
                    
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="LfrlAnvil.Computable.Expressions" Version="0.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LfrlAnvil.Computable.Expressions" Version="0.4.0" />
                    
Directory.Packages.props
<PackageReference Include="LfrlAnvil.Computable.Expressions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LfrlAnvil.Computable.Expressions --version 0.4.0
                    
#r "nuget: LfrlAnvil.Computable.Expressions, 0.4.0"
                    
#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.
#:package LfrlAnvil.Computable.Expressions@0.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LfrlAnvil.Computable.Expressions&version=0.4.0
                    
Install as a Cake Addin
#tool nuget:?package=LfrlAnvil.Computable.Expressions&version=0.4.0
                    
Install as a Cake Tool

(root) NuGet Badge

<img src="../../../../assets/logo.png" alt="logo" height="80"/> LfrlAnvil.Computable.Expressions

This project contains a parser of string expressions that can be compiled to invocable delegates.

Documentation

Technical documentation can be found here.

Examples

Following contains an example of a parser configuration, as well as creation, compilation and invocation of a delegate:

// creates a builder of a minimal parser capable of supporting most arithmetic and logical operators
// and branching functions, like 'if' and 'switch'
// in addition, it will try to parse all constant numbers as 32-bit signed integers
// instead of the default decimal type
var builder = new ParsedExpressionFactoryBuilder()
    .AddGenericArithmeticOperators()
    .AddGenericBitwiseOperators()
    .AddGenericLogicalOperators()
    .AddBooleanLogicalOperators()
    .AddStringArithmeticOperators()
    .AddBranchingVariadicFunctions()
    .SetNumberParserProvider( p => ParsedExpressionNumberParser.CreateDefaultInt32( p.Configuration ) );

// builds an expression parser
var parser = builder.Build();

// string expression to parse, that contains two external arguments: 'a' and 'b'
var input =
    """
    let x = (a + 1).ToString();
    let y = if(x.Length > 1, b * 2, b * 4).ToString();
    y + x + y;
    """;

// creates a parsed expression from the given string input
var expression = parser.Create<int, string>( input );

// compiles the expression to an invocable delegate
var func = expression.Compile();

// invokes the delegate with 'a' = 42 and 'b' = 31,
// which should return '624362'
var result = func.Invoke( 42, 31 );
Product Compatible and additional computed target framework versions.
.NET 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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on LfrlAnvil.Computable.Expressions:

Package Downloads
LfrlAnvil.MessageBroker.Server

This project contains server-side message broker implementation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.4.0 99 3/14/2026
0.3.0 216 1/7/2025
0.2.1 215 6/16/2024
0.2.0 176 6/16/2024
0.1.1 180 5/29/2024
0.1.0 190 5/26/2024