I'm trying to create a nested Guard method (or find an existing Guard library) that would throw an exception if any object in a nested hierarchy is NULL and include the name of the object hierarchy path up to and including NULL. I also want to avoid fluent API syntax of checking each object. Please assume example below.
Assume the following hierarchy:
Country.State.City.Person
Example of usage I'm trying to achieve:
Guard.ThrowIfNull(Country.State.City.Person);
or
Guard.ThrowIfNull(() => Country.State.City.Person);
EXPECTED RESULT:
if Person is NULL, then throw ArgumentNullException("Country.State.City.Person")
if City is NULL, then throw ArgumentNullException("Country.State.City")
if State is NULL, then throw ArgumentNullException("Country.State")
if Country is NULL, then throw ArgumentNullException("Country")