Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // =======================
- // Alternativa: Métodos de Extensão (explícitos e desacoplados)
- // Úteis quando você prefere evitar operadores.
- // =======================
- public static class PedidoMappingExtensions
- {
- public static Pedido ToDomain(this PedidoDto dto)
- {
- if (dto is null) throw new ArgumentNullException(nameof(dto));
- if (string.IsNullOrWhiteSpace(dto.Id)) throw new ArgumentException("Id obrigatório no DTO");
- if (string.IsNullOrWhiteSpace(dto.Cliente)) throw new ArgumentException("Cliente obrigatório no DTO");
- if (dto.Data is null) throw new ArgumentException("Data obrigatória no DTO");
- if (dto.Total is null) throw new ArgumentException("Total obrigatório no DTO");
- return Pedido.Criar(dto.Id!, dto.Cliente!, dto.Data.Value, dto.Total.Value);
- }
- public static PedidoDto ToDto(this Pedido model)
- {
- if (model is null) throw new ArgumentNullException(nameof(model));
- return new PedidoDto
- {
- Id = model.Id,
- Cliente = model.Cliente,
- Data = model.Data,
- Total = model.Total
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment