Pattern-based C#: if it quacks like a duck…
summary
Live coding shows exactly what shapes the Roslyn compiler recognizes and how to teach it new ones: a source generator and a manual Deconstruct method enable tuple deconstruction for a plain class, adding an Add method plus collection builder attribute gives collection and span-backed initialization, custom GetEnumerator and ref struct enumerator enable foreach without IEnumerable, an own custom awaiter and async enumerator let await and await foreach work, a bespoke async method builder and interpolated string handler are implemented, and a benchmark proves interface enumeration boxes and allocates.
AI-written summary · about
chapters (25)
- 0:00Compiler patterns in C#
- 1:58Deconstructing without interfaces
- 7:17Method shape for deconstruction
- 10:03Collection initialization patterns
- 11:50Collection initializer support
- 13:13Dictionary initialization with Add
- 15:23Optimizing with CollectionBuilder
- 19:42Indexing with implicit syntax
- 21:50Enabling implicit indexing
- 24:17Slicing with Range and FromEnd
- 26:45Slice method for collections
- 28:30Foreach without IEnumerable
- 30:58Custom enumerators for foreach
- 34:52Async disposal for ref structs
- 35:55Awaiting any type
- 41:01Extending awaitable types
- 43:35Custom awaiters for await
- 47:33Returning values from awaiters
- 48:36Live quiz
- 48:57Async method builder patterns
- 51:24Interpolated string handlers
- 53:08Custom string handlers example
- 54:31Non-extendable patterns
- 57:46Performance impact of static typing
- 59:54Q&A








