João Simões
Jun 10, 2023

--

The problem with "implicit/explicit" is that you can only define them inside the class definition.

This may be acceptable for some cases, but most of the time it isn't because either you don't have control of the classes (some external library) or, and this is the most common, you are mapping DTOs from different layers and you don't want to tie them, breaking SOLID principles.

I think extension methods are much well suited for this purpose. You can isolate them in a dedicated class for mappings inside the implementation projects, they ensure the conversion is always explicit and you can easily debug them, something you can't do with mapping libraries.

--

--

João Simões
João Simões

Written by João Simões

Solutions Architect trying to solve world “problems”! Creator of https://code-corner.dev

Responses (4)