Created
February 3, 2014 16:16
-
-
Save JohnLBevan/d96780f5aa12bd2f86d3 to your computer and use it in GitHub Desktop.
ToStringIfNotNull; allows me to write `return o.ToStringIfNotNull();` instead of `return o==null?null:o.ToString();` ; i.e. a ToString function which can cope with null references.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ObjectExtensions | |
{ | |
public static string ToStringIfNotNull(this object o) | |
{ | |
return o == null ? null : o.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment