Created
February 27, 2014 20:28
-
-
Save brandon-barker/9258851 to your computer and use it in GitHub Desktop.
An extension method for checking if an object is null
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 NotNullExtension | |
{ | |
public static TResult IfNotNull<TSource, TResult>(this TSource source, Func<TSource, TResult> accessor, TResult @default = default(TResult)) | |
where TSource : class | |
{ | |
return source != null | |
? accessor(source) | |
: @default; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment