I need to implement a repository class that can let user search on different field of an object. After retrieve data from another service, I save the result to a Dictionary
object, now I want to able filter result based on different object's properties. For example:
People {
public string FirstName {get; set;}
public string LastName {get; set;}
}
Dictionary<int, People> rawData;
public List<People> GetByFirstName(string firstName) {
if(string.IsNullOrEmpty(firstName)) {
return new List<People>();
}
return rawData.Where(p => p.FirstName == firstName).ToList(i => i.Value);
}
public List<People> GetByLastName(string lastName) {
if(string.IsNullOrEmpty(lastName)) {
return new List<People>();
}
return rawData.Where(p => p.LastName == lastName).ToList(i => i.Key, i => i.Value);
}
Now I want to implement some sort of prototype pattern by using a helper function:
public List<People> SearchHelper(string searchValue, //need to change so that another can pass condition in here) {
if(string.IsNullOrEmpty(lastName)) {
return new List<People>();
}
return rawData.Where(// need to put customize condition here).ToList(i => i.Value);
}
The reason I want to have a prototype pattern here because I have ton of object's properties. Any suggestions are appreciated.