Runtime code generation techniques in real life scenarios
summary
Shows concrete patterns: building fast delegates from Expression Trees to replace reflection, parsing spreadsheet-like formulas into expression lambdas, and generating object mappers that compile a Dictionary-to-POCO assignment with cast and null checks. Demonstrates source-level generation and debugging via Roslyn/CodeAnalisys (emit formatted C#, add DebuggableAttribute, step into generated code) and runtime IL rewriting with ILSpy-style instrumentation to inject logs and produce execution flow diagrams. Notes practical pitfalls like implicit conversion handling and async/Task<T> marshaling.
AI-written summary · about
chapters (11)
- 0:00Introduction and speaker background
- 1:51What is code generation
- 4:29When to generate code
- 7:21Using expressions for code generation
- 13:30Building a custom parser
- 21:05Mapping objects to dictionaries
- 34:04Advanced code generation with Roslyn
- 46:20High-level abstractions in Roslyn
- 51:20Why not use IL directly
- 57:06Runtime IL instrumentation demo
- 1:01:25Summary and key takeaways
