Luke Smith Write today, wrong tomorrow

ASP.NET PageHelper

Since moving from university to the 'real' world of development I've been creating
alot of helper classes to try and cut down on the number of LOC I have to write. One
thing which bugged me for a while was Query Strings in ASP.NET - checking whether
a string existed and then getting that strings value. Sounds simple but then what
if you're expecting it to be an integer or a double, or a DateTime or something else?
You have to go through the checking then the converting to the type you want.

So instead of

string querystring = Request.QueryString["myinteger"]; if (!string.IsNullOrEmpty(querystring)) { int output; if (int.TryParse(querystring, out output) { // the querystring was actually an integer } }

>

I wrote a helper class that will return a nullable
type
of the QueryString value giving cleaner code in the page and reducing the
chances of not catching exceptions, as you can never be 100% the querystring you expect
to be an integer will be an integer

int? output = PageHelper.GetQueryInt("myinteger"); if (output.HasValue) { // output is an integer }

>

I am finishing off a code viewer for my website, so i will soon be making the PageHelper
and other helper classes available.

comments powered by Disqus