mardi 25 juin 2019

A good design to conditionaly include/exclude property

For a web application, I have a service that get some information. For example a SaleOrder and SaleOrderDto which contains a few dozen of properties

  • OrderID
  • Date
  • Total amount
  • Total item count

... etc etc...

Asusme that some of the properties take time to call external services to include, I would like to have a mechanic that let user select/reject some properties for their call

For Example:

/service/order/1/info?include=OrderID,TotalAmount

I do not really like to do something like

if(OrderID)
{
   OrderDTO.OrderID = Order.OrderID
}
if(TotalAmount)
{
   OrderDTO.TotalAmount = Order.TotalAmount
}

Or using Reflection to loop through all properties

Can you help me with some suggestion to make cleaner code?

Aucun commentaire:

Enregistrer un commentaire