How can I use a coalesce operator in a DRY way; when assigned value is null, keep own value

93 Views Asked by At

I am sending value in object orderContract which will replace values of entity if contract value is not null but if contract property is null it will retain its own value.

Currently I have used coalesce operator as in 2nd line of code. Is there a way where I don't have to repeat existing value?

 var ordersEntity = _repository.Read<Entities.Orders>(orderContract.Id);

ordersEntity.Status = orderContract.Status ?? ordersEntity.Status;
0

There are 0 best solutions below