Skip to content

Instantly share code, notes, and snippets.

@troufster
Created December 18, 2012 15:52
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 troufster/4329175 to your computer and use it in GitHub Desktop.
Save troufster/4329175 to your computer and use it in GitHub Desktop.
public static bool HasValue<T, TP>(T value, Expression<Func<T,TP>> property) {
try {
var memberExpression = (MemberExpression)property.Body;
var prop = (PropertyInfo)memberExpression.Member;
//Attempt to resolve
var val = prop.GetValue(value);
return val != null;
}
catch {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment