Last active
March 15, 2016 15:18
-
-
Save jesuslpm/512ddc1fecaef4644709 to your computer and use it in GitHub Desktop.
Ayende csv user data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class UserData | |
| { | |
| public int Id { get; set; } | |
| public string Email { get; set; } | |
| } | |
| public class UserDataSearcher | |
| { | |
| private readonly Dictionary<string, List<int>> userIdsByEmail; | |
| public UserDataSearcher(IEnumerable<UserData> usersData) | |
| { | |
| userIdsByEmail = new Dictionary<string, List<int>>(StringComparer.InvariantCultureIgnoreCase); | |
| foreach (var userData in usersData) | |
| { | |
| List<int> userIdList; | |
| if (! userIdsByEmail.TryGetValue(userData.Email, out userIdList)) | |
| { | |
| userIdList = new List<int>(); | |
| userIdsByEmail.Add(userData.Email, userIdList); | |
| } | |
| userIdList.Add(userData.Id); | |
| } | |
| } | |
| public IEnumerable<int> GetUserIdsByEmail(string email) | |
| { | |
| List<int> userIdList; | |
| if (userIdsByEmail.TryGetValue(email, out userIdList)) | |
| { | |
| return userIdList; | |
| } | |
| return Enumerable.Empty<int>(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment