Skip to content

hannasm/ExpressiveExpressionTreesDotNet

Repository files navigation

Versioning

This is version 2.1.0 of the Expressive Expression Tree library.

This package is available on nuget at: https://www.nuget.org/packages/ExpressiveExpressionTrees/2.1.0

The source for this package is available on github at: https://github.com/hannasm/ExpressiveExpressionTreesDotNet/releases/tag/2.1.0

Source Packages

The dotnet core releases to date do not support source code transformations, which was an essential feature for the source only distribution of this project. The source only distributions has been discontinued until this feature makes it back into the dotnet core featureset.

ExpressiveExpressionTreesDotNet

This is a library that simplifies creating / manipulating expression trees. This includes various expression tree related utilities that are useful but without a better place to live.

What's Included

  • ExpressionGenerator - leverages the Expression<Func<...>> / Expression<Action<...>> language feature to support expressive creation of expression trees
  • ExpressionVisitor - custom implementation of the visitor pattern on expression trees
  • ExpressionComparer - custom implementation of the visitor pattern on expression trees to compare two instances
  • ExpressionReplacer - derivation of the ExpressionVisitor to replace subexpressions
  • ExpressionHasher - derivation of the ExpressionVisitor to create a valid hashcodes for an expression tree
  • ExpressionFinder - derivation of the ExpressionVistior to determine whether one expression exists within another expression tree
  • ExpressionReader - collection of utitlity methods useful when manipulating expression trees

Expression Generator

The expression generator is the Expressive part of the ExpressiveExpressionTrees library. With it, you can leverage the C# compiler to produce expression trees for you from static C# source code. These compiler generated expression trees are easily manipulated and recompiled later into executable code.

var xgr = new ExpressiveExpressionTrees.ExpressionGenerator();

// create an expression tree for instantiating a new anonymous type
var e1 = xgr.FromFunc(()=>new {
  FieldOne = 1,
  FieldTwo = "ABC"
});

// create an expression tree for writing hello world to the console
var e2 = xgr.FromAction(()=>Console.WriteLine("Hello World"));

// create an expression tree for returning the length of a string parameter
// demonstrating the use of the lambda parameters and strongly typed expression substitutions
var p1 = Expression.Lambda<Func<string>>(Expression.Parameter(typeof(string)));
var e3 = xgr.FromFunc(p1, (s)=>s.Length);

Expression Hasher / Expression Comparer

The ExpresisonHasher and ExpressionComparer are useful in a number of different contexts because they allow for Expression trees to be stored inside of a dictionary / hashtable data structure as a key. The hasher / comparer are based on field level equality, and not reference equality, meaning that two distinct instances of an expression tree composed of the exact same expression will be treated as equal.

Release Notes

For Release Notes See Here

About

Library that simplifies creating / manipulating expression trees

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages