The BuildableExpressions configuration API enables creation of classes, structs, interfaces, enums and attributes, with Expressions used to implement method bodies and property accessors.

Expressions vs Strings

The BuildableExpression.SourceCode() factory method can take a C# source-code string, which depending on your scenario could be simpler and faster.

So why use Expressions?

  • To implement methods using complex Expression Trees built by existing code - perhaps to move runtime logic to build-time

  • To write more refactor-friendly code - source code strings cannot be statically checked and have no design-time safety

  • Expression Tree code compilation or generation handles referencing required assemblies for you

Ultimately, you may just find it simpler to build strings. The best use case for using Expressions is to move an existing runtime operation - e.g creating object-object mappers - to build-time.