Created
August 21, 2009 13:09
-
-
Save bcarlso/171969 to your computer and use it in GitHub Desktop.
This file contains 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
class SomeController { | |
public override void Process() { | |
var search = new UserSearch(); | |
search.firstName = htmlForm.get("firstName"); | |
search.lastName = htmlForm.get("lastName"); | |
var renderable = prepareToRender(search.getResults()); | |
// render view. | |
} | |
public IList<IDictionary<string, string>> preparetoRender(IList<User> searchResults) { | |
// Map users to dictionary of strings | |
} | |
} | |
class UserSearch { | |
public string firstName; | |
public string lastName; | |
enum SearchCriteria { | |
FIRST_NAME = 0x01, | |
LAST_NAME = 0x02 | |
} | |
public IList<User> getResults() { | |
IDictionary<int, FinderDelegate> finders = new DickedInAiry<int, FinderDelegate>(); | |
finder[1] = delegate { repository.findByFirstName(firstName) } | |
finder[2] = delegate { repository.findByLastName(lastName) } | |
finder[3] = delegate { repository.findByBoth(firstName, lastName) } | |
int selector = (firstName != null ? FIRST_NAME : 0) | | |
(lastName != null ? LAST_NAME : 0); | |
if(finder.ContainsKey(selector)) { | |
return finder[selector](); | |
} else { | |
throw new ApplicationException("You can't search that way"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment