Expression trees in C#
summary
Explains what C# expression trees are, shows manual construction with System.Linq.Expressions and compiling them to IL, and benchmarks calling a private method: reflection (slow) → cached MethodInfo → Delegate.CreateDelegate → compiled expression (fastest), with dynamic about 20x slower. Builds a generic three‑quarters operator via compiled expressions, a small calculator DSL parsed with Sprache into Expression trees and compiled, and an ExpressionVisitor that rewrites sin to cos — all working as demonstrated.
AI-written summary · about
chapters (9)
- 0:00Intro
- 0:11Expression Trees in C#
- 5:36Expression Tree describes the structure of an expression
- 6:51Constructing Expression Trees Manually
- 14:07Optimizing Reflection Heavy Code
- 19:54Implementing Generic Operators
- 25:40Parsing DSLs into Expression Trees
- 36:41Preserving Source Code in Assertions
- 43:12Transpiling Code into a Different Language
related talks
43mBeyond LINQ: Using Expression Trees in .NET
51mUsing C# Expression Trees in the Real World
44mEFCore - Expression trees climbing
32mDeep Dive into Computational Expressions in F#
50mExpression Templates: Past, Present, Future
59mExpression Templates: Past, Present, Future
56mLowering in C#: What's really going on in your code?
52mPerformance features in C#
