I want to call constructor of the class only if my object is not null. I can do it with "if else" but I have a lot of assignment like that and want to make it short. How can I write operator like null assignment "??" but it will work reverse.
From
LastMessage = item.LastMessage != null ? new MessageViewModel(item.LastMessage) : null;
To
LastMessage = item.LastMessage !? new MessageViewModel(item.LastMessage);
or (I am not sure this one gonna work but seems nice to me :) )
LastMessage = ? new MessageViewModel(item.LastMessage);