Hyperbee.Expressions 1.4.7

dotnet add package Hyperbee.Expressions --version 1.4.7
                    
NuGet\Install-Package Hyperbee.Expressions -Version 1.4.7
                    
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="Hyperbee.Expressions" Version="1.4.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hyperbee.Expressions" Version="1.4.7" />
                    
Directory.Packages.props
<PackageReference Include="Hyperbee.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 Hyperbee.Expressions --version 1.4.7
                    
#r "nuget: Hyperbee.Expressions, 1.4.7"
                    
#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 Hyperbee.Expressions@1.4.7
                    
#: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=Hyperbee.Expressions&version=1.4.7
                    
Install as a Cake Addin
#tool nuget:?package=Hyperbee.Expressions&version=1.4.7
                    
Install as a Cake Tool

Welcome to Hyperbee Expressions

This repository contains libraries for extending and compiling C# expression trees.

Packages

Package Description
Hyperbee.Expressions Extended expression tree nodes for async workflows, iterators, resource management, and looping constructs.
Hyperbee.Expressions.Compiler A high-performance, IR-based expression compiler that is 9-34x faster than the System compiler with correct IL across all expression tree patterns.

Hyperbee.Expressions

Hyperbee.Expressions extends the capabilities of standard expression trees to handle asynchronous workflows and other language constructs.

Features

  • Async Expressions

    • AwaitExpression: An expression that represents an await operation.
    • AsyncBlockExpression: An expression that represents an asynchronous code block.
  • Yield Expressions

    • YieldExpression: An expression that represents a yield return or break statement.
    • EnumerableBlockExpression: An expression that represents an enumerable code block.
  • Using Expression

    • UsingExpression: An expression that automatically disposes IDisposable resources.
  • Looping Expressions

    • WhileExpression: An expression that represents a while loop.
    • ForExpression: An expression that represents a for loop.
    • ForEachExpression: An expression that represents a foreach loop.
  • Other Expressions

    • StringFormatExpression: An expression that creates a string using a supplied format string and parameters.
    • ConfigurationExpression: An expression that allows access to IConfiguration.
    • InjectExpression: An expression that allows for depency inject from a IServiceProvider.
    • DebugExpression: An expression that helps when debugging expression trees.
  • Supports Fast Expression Compiler (FEC) for improved performance.

  • Supports interpreted expression trees using lambda.Compile(preferInterpretation: true).

    var lambda = Expression.Lambda<Func<int>>(Expression.Constant(1));
    var interpetedLambda = lambda.Compile(preferInterpretation: true);
    

Examples

Asynchronous Expressions

The following example demonstrates how to create an asynchronous expression tree.

When the expression tree is compiled, the AsyncBlockExpression will auto-generate a state machine that executes AwaitExpressions in the block asynchronously.


public class Example
{
    public async Task ExampleAsync()
    {
        // Create an async block that calls async methods and assigns their results
        var instance = Constant( this );
        var result1 = Variable( typeof(int), "result1" );
        var result2 = Variable( typeof(int), "result2" );

        var asyncBlock = BlockAsync(
            [result1, result2],
            Assign( result1, Await(
                Call( instance, nameof(FirstAsyncMethod), Type.EmptyTypes )
            ) ),
            Assign( result2, Await(
                Call( instance, nameof(SecondAsyncMethod), Type.EmptyTypes, result1 )
            ) )
        );

        // Compile and execute the async block
        var lambda = Lambda<Func<Task<int>>>( asyncBlock );
        var compiledLambda = lambda.Compile();
        var resultValue2 = await compiledLambda();

        Console.WriteLine( $"Second async method result: {resultValue2}" );
    }

    public static async Task<int> FirstAsyncMethod()
    {
        await Task.Delay( 1000 ); // Simulate async work
        return 42; // Example result
    }

    public static async Task<int> SecondAsyncMethod( int value )
    {
        await Task.Delay( 1000 ); // Simulate async work
        return value * 2; // Example result
    }
}
Yield Expressions

The following example demonstrates how to create a yield expression tree.

When the expression tree is compiled, the EnumerableBlockExpression will auto-generate a state machine that executes YieldExpressions in the block.

public class Example
{
    public void ExampleYield()
    {
        // Create an enumerable block that yields values
        var index = Variable( typeof(int), "index" );

        var enumerableBlock = BlockEnumerable(
            [index],
            For( Assign( index, Constant( 0 ) ), LessThan( index, Constant( 10 ) ), PostIncrementAssign( index ),
                Yield( index )
            )
        );

        // Compile and execute the enumerable block
        var lambda = Lambda<Func<IEnumerable<int>>>( enumerableBlock );
        var compiledLambda = lambda.Compile();
        var enumerable = compiledLambda();

        foreach( var value in enumerable )
        {
            Console.WriteLine( $"Yielded value: {value}" );
        }
    }
}
Using Expression

The following example demonstrates how to create a Using expression.

public class Example
{
    private class DisposableResource : IDisposable
    {
        public bool IsDisposed { get; private set; }
        public void Dispose() => IsDisposed = true;
    }

    public void ExampleUsing()
    {
        var resource = new TestDisposableResource();

        var disposableExpression = Expression.Constant( resource, typeof( TestDisposableResource ) );
        var bodyExpression = Expression.Empty(); // Actual body isn't important

        var usingExpression = ExpressionExtensions.Using( 
            disposableExpression, 
            bodyExpression 
        );

        var compiledLambda = Expression.Lambda<Action>( reducedExpression ).Compile();

        compiledLambda();

        Console.WriteLine( $"Resource was disposed {resource.IsDisposed}." );
    }
}

Hyperbee.Expressions.Compiler

A high-performance, IR-based expression compiler for .NET. Drop-in replacement for Expression.Compile() that is 9-34x faster and allocates up to 50% less than the System compiler and supports all expression tree patterns -- including those that FastExpressionCompiler doesn't.

Quick Start

dotnet add package Hyperbee.Expressions.Compiler
using Hyperbee.Expressions.Compiler;

// Direct compilation -- drop-in replacement for Expression.Compile()
var lambda = Expression.Lambda<Func<int, int, int>>(
    Expression.Add( a, b ), a, b );

var fn = HyperbeeCompiler.Compile( lambda );
var result = fn( 1, 2 ); // 3

// Or use the extension method
var fn = lambda.CompileHyperbee();

For benchmarks, architecture details, and advanced usage, see the full Hyperbee.Expressions.Compiler README.

Credits

Special thanks to:

Contributing

We welcome contributions! Please see our Contributing Guide for more details

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 is compatible.  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 is compatible.  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 (4)

Showing the top 4 NuGet packages that depend on Hyperbee.Expressions:

Package Downloads
Hyperbee.XS

XS: A Lightweight, Extensible Scripting Language for Expression Trees.

Hyperbee.XS.Extensions

Expression Script [XS] language extensions.

Hyperbee.Expressions.Lab

Sample Extentions for .NET Expression Trees.

Hyperbee.Expressions.Compiler

High-performance IR-based expression compiler for .NET.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.4.7 86 4/12/2026
1.4.6 128 3/9/2026
1.4.1 106 3/1/2026
1.4.0 124 2/5/2026
1.3.2 511 1/21/2026
1.3.2-alpha-gceee054548 126 1/21/2026
1.2.1 131 12/29/2025
1.2.0 1,308 5/9/2025
1.2.0-develop.250417163546 230 4/17/2025
1.1.5 519 4/2/2025
1.1.5-develop.250402163927 205 4/2/2025
1.1.5-develop.250402142908 169 4/2/2025
1.1.5-develop.250402133114 189 4/2/2025
1.1.5-develop.250402131116 184 4/2/2025
1.1.5-develop.250401194515 173 4/1/2025
1.1.4 292 3/31/2025
1.1.4-develop.250331172856 198 3/31/2025
1.1.4-develop.250328154856 183 3/28/2025
1.1.3 313 3/19/2025
1.1.3-develop.250319162912 185 3/19/2025
Loading failed