Может быть что-то вроде Dictionary<string, HashSet<string>>
?
Например:
var pairs = new[] {
new{Role="user",Permission="addItem"},
new{Role="admin",Permission="removeItem"},
new{Role="admin",Permission="advancedSearch"},
new{Role="guest",Permission="simpleSearch"},
new{Role="user",Permission="addItem"},
new{Role="manager",Permission="editUser"},
};
Dictionary<string, HashSet<string>> cache = pairs.GroupBy(pair => pair.Role)
.ToDictionary(grp => grp.Key, grp => new HashSet<string>(
grp.Select(g => g.Permission)));
cache["user"].Contains("addItem");
Или при чтении из устройства чтения данных (комментарий):
var cache = new Dictionary<string, HashSet<string>>();
using (var reader = GetReader()) {
while (reader.Read()){
string role = reader.GetString(0),
permission = reader.GetString(1);
HashSet<string> permissions;
if (!cache.TryGetValue(role, out permissions)){
cache.Add(role, permissions = new HashSet<string>());
}
permissions.Add(permission);
}
}