Skip to content

Instantly share code, notes, and snippets.

@brandon-barker
Created February 27, 2014 20:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brandon-barker/9258851 to your computer and use it in GitHub Desktop.
Save brandon-barker/9258851 to your computer and use it in GitHub Desktop.
An extension method for checking if an object is null
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