I have a class with many bool properties. How can I create another property that is a list of strings that contains the name of properties that are true?
See initial attempt below - cannot understand how to filter true
public class UserSettings
{
public int ContactId { get; set; }
public bool ShowNewLayout { get; set; }
public bool HomeEnabled { get; set; }
public bool AccountEnabled { get; set; }
public IEnumerable<string> Settings
{
get
{
return GetType()
.GetProperties()
.Where(o => (bool)o.GetValue(this, null) == true)
.Select(o => nameof(o));
}
}
}
source
share