Created
March 16, 2012 22:08
-
-
Save monoman/2053145 to your computer and use it in GitHub Desktop.
Some things that could make ASP.NET MVC 4 Web API even better
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
// this offends my coding sensibility | |
public Contact GetContact(int id) | |
{ | |
Contact contact = _repository.Get(id); | |
if (contact == null) | |
{ | |
throw new HttpResponseException(HttpStatusCode.NotFound); | |
} | |
return contact; | |
} | |
// most of it could become a extension method | |
public static T VerifiedToExist<T>(this T it) | |
{ | |
if (it == null) | |
{ | |
throw new HttpResponseException(HttpStatusCode.NotFound); | |
} | |
return it; | |
} | |
// so the action would become | |
public Contact GetContact(int id) | |
{ | |
return _repository.Get(id).VerifiedToExist(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment