Phil Haack wrote about this a while ago. Basically, it offers an extension method to string that allows you to do
var text = someString.AsNullIfEmpty() ?? "Not provided.";
The extension method is very simple:
public static string AsNullIfEmpty(this string str) { return !string.IsNullOrEmpty(str) ? str : null; }
It also offers version checking for spaces instead of empty using the string.IsNullOrWhitespace() method from .NET 4, as well as similar extensions for the IEnumerable<T> interface.
He also talks about introducing new operators for this, such as ??? but concludes that this will be more confusing than useful. In the end, by introducing these extension methods, you can do the same, but it is more readable, and this is using a shorthand syntax that "everyone already knows."
Tomas lycken
source share