Skip to content

Instantly share code, notes, and snippets.

@bmorrisondev
Created November 4, 2019 16:20
Show Gist options
  • Select an option

  • Save bmorrisondev/ea7e9e2d57a017b2b7ff69f64a68fdc7 to your computer and use it in GitHub Desktop.

Select an option

Save bmorrisondev/ea7e9e2d57a017b2b7ff69f64a68fdc7 to your computer and use it in GitHub Desktop.
Returns false if all members of an object are null
/// <summary>
/// Iterates through an object's properties and checks of any of them are null.
/// </summary>
public static bool AllPropertiesNullOrEmpty(this object theObject)
{
var propertiesNotNull = theObject.GetType()
.GetProperties()
.Select(pi => pi.GetValue(theObject))
.Any(value => value != null);
if(propertiesNotNull)
{
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment