I've been looking and found this which describes to return a bool if value is null. The code, I'm using is from this snippet Client client = new Client{ FirstName = "James"};
client.GetType().GetProperties()
.Where(pi => pi.GetValue(client) is string)
.Select(pi => (string) pi.GetValue(client))
.Any(value => string.IsNullOrEmpty(value));
But instead of returning if the value is null or not (the bool) I would like to retrieve all the properties values where they are not null.
I've tried making changes to the code, but unsuccessful.
Many thanks
EDIT
public class Client
{
public string FirstName { get; set; }
public string LastName { get; set; }
//...
}
Client client = new Client();
client.FirstName = "James";
client.LastName = "";
Using my 'Client' class, I would like to iterate over all the properties within my class, and where the value isn't null or empty string, I would return the value, in this example, I would only return a string "James".
Hope that makes sense.