项目作者: AndreyChechel

项目描述 :
Closure-free C# Expressions
高级语言: C#
项目地址: git://github.com/AndreyChechel/Explosuress.git
创建时间: 2020-05-09T20:11:03Z
项目社区:https://github.com/AndreyChechel/Explosuress

开源协议:MIT License

下载


Explosuress

NuGet Status

Closure-free C# Expressions.

Explosuress processes an Expression Tree and removes all closures by evaluating and replacing them with corresponding values. This operation reduces size and memory footprint of the tree.

Installation

  1. Install the NuGet package:
  1. Install-Package Explosuress

or

  1. dotnet add package Explosuress
  1. Add using statement:
  1. using System.Linq.Expressions;
  1. Call the Explosuress() extension method to process an expression:
  1. var closureFreeExpr = expression.Explosuress();

Example

Consider the Expression Tree shown below:

  1. var local = new Local
  2. {
  3. Field = 123
  4. };
  5. Expression<Func<int, bool>> expression =
  6. x => local.Field == x;
  7. Console.WriteLine(expression);

The tree structure contains a closure to local.Field:

  1. x => (value(Explosuress.Demo.Program+<>c__DisplayClass0_0).local.Field == x)

Explosuress can remove the closure:

  1. var closureFreeExpr = expression.Explosuress();
  2. Console.WriteLine(closureFreeExpr);

This is how the closure-free structure will look like:

  1. x => (123 == x)

License

MIT