It is a bit of a weird use case, but I had a method where an IDisposable object is potentially passed as an argument (and therefore disposed by the parent), but it could also be null (and so should be created and disposed in a local method)
To use it, the code either looked like
Channel channel;
Authentication authentication;
if (entities == null)
{
using (entities = Entities.GetEntities())
{
channel = entities.GetChannelById(googleShoppingChannelCredential.ChannelId);
[...]
}
}
else
{
channel = entities.GetChannelById(googleShoppingChannelCredential.ChannelId);
[...]
}
But with a null coalesce it becomes much neater:
using (entities ?? Entities.GetEntities())
{
channel = entities.GetChannelById(googleShoppingChannelCredential.ChannelId);
[...]
}