The domain types that we define can be quite complex, yet the corresponding DTO types must be simple structures containing only primitive types. How then do we design a DTO given a particular domain type? Let’s look at some guidelines.
Single-case unions—what we are calling “simple types” in this book—can be represented by the underlying primitive in the DTO.
For example, if ProductCode is this domain type:
|||type ProductCode = ProductCode of string|
Then the corresponding DTO type is just string.
For options, we can replace the None case with null. If the option wraps a reference type, we don’t need to do anything because null is a valid value. For value types like int, we’ll ...