I frequently make use of Request.QueryString[] variables.
In my Page_load I often do things like:
int id = -1; if (Request.QueryString['id'] != null) { try { id = int.Parse(Request.QueryString['id']); } catch { // deal with it } } DoSomethingSpectacularNow(id);
It all seems a bit clunky and rubbish. How do you deal with your Request.QueryString[]s?
Below is an extension method that will allow you to write code like this:
It makes use of
TypeDescriptorto perform the conversion. Based on your needs, you could add an overload which takes a default value instead of throwing an exception: