Skip to content

Instantly share code, notes, and snippets.

@hanssens
Created July 23, 2015 14:29
Show Gist options
  • Save hanssens/2e58004bbdd3f4b9e344 to your computer and use it in GitHub Desktop.
Save hanssens/2e58004bbdd3f4b9e344 to your computer and use it in GitHub Desktop.
Extension for checking if all properties in an object contains values with null
public static bool IsAnyNullOrEmpty(this object obj)
{
// could be less verbose, in on linq query,
// but it would come at the cost of readability
foreach (var pi in obj.GetType().GetProperties())
{
var value = (string)pi.GetValue(obj);
if (string.IsNullOrEmpty(value)) return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment