Blog
Mert Özen's blog posts on software development, backend, frontend, and DevOps.
Iterator and Interpreter: Two Patterns Built into C# — yield return and Expression Trees
Iterator lets you walk a collection's elements in order without exposing its internals, and in C# it is built into the language as IEnumerable, IEnumerator and yield return; Interpreter represents a small language's grammar as an AST and evaluates it. With real output we read a paged catalog API with yield and IAsyncEnumerable, write a small promotion rule language and compile it to an expression tree, look at the interpreter inside Regex and draw the security boundary for dynamic expressions.
Visitor Pattern: Double Dispatch, ExpressionVisitor and a Comparison with Pattern Matching
Visitor doubles C#'s one-dimensional virtual dispatch through Accept and Visit calls, letting you add new operations to a stable type hierarchy without touching the elements; the price is that a new type breaks every visitor. The static-type trap of overload resolution, the expression problem, ExpressionVisitor and Roslyn's CSharpSyntaxWalker, and a comparison with switch expressions that have no exhaustiveness check.