Created
July 23, 2015 14:29
-
-
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
This file contains 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 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