Say I have an object:
public class Person
{
public IDictionary<string, string> RoleTypes { get; set; }
}
Where the roletypes have a name as a key and a description as a value:
- Manager: The manager who does stuff
- CIO: Who knows what they do
- CEO: No one knows what they do.
So now I have say a list of People:
IEnumerable people;
I want to somehow get back from that list the person who is the CEO:
people.Single(x => x.RoleTypes.Contains("CEO"));
Well that doesn’t even compile.
Anyone know how to get it to work?
You have to check the keys (if the title is the key of the dictionary):
That being said, this data organizational structure is odd – it would make more sense to keep the titles and descriptions separate, so they aren’t duplicated within each person. The user could maintain just a list of their titles, and the desciption of that title could be looked up elsewhere.