Created
November 4, 2019 16:20
-
-
Save bmorrisondev/ea7e9e2d57a017b2b7ff69f64a68fdc7 to your computer and use it in GitHub Desktop.
Returns false if all members of an object are null
This file contains hidden or 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
| /// <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