I have a flagged enum and need to retrieve the names of all values set on it.
I am currently taking advantage of the enum's ToString() method which returns the elements comma-separated.
public void SetRoles(Enums.Roles role)
{
IList<Entities.Role> roleList = role.ToString("G").Split(',')
.Select(r => new Entities.Role(r.Trim()))
.ToList();
...
}
I'm sure there must be a better way than this.