Switch Expression or Visitor pattern
12/07/2024
A few months ago I looked into optimizing dictionary lookups using switch expressions.
In this post I investigate a seemingly similar problem, but with vastly different constraints, that eventually demand a vastly different solution.
Problem Definition
Given a set of polymorphic objects and a DTO. A method needs to iterate all the polymorphic objects and evaluate them against the DTO. Each polymorphic object evaluates a different (C#) property of the DTO. While there are a few designs to achieve this, in this case I seek for a design that does not introduce a coupling between the polymorphic objects and the DTO. I compare two possible solutions in this post.