Saturday, February 5, 2011

Generics and casting

I often find myself creating methods which return a generic type.  For instance, on a recent project I have been dealing with a lot of XML.  Instead of casting the value of an XAtrribute to an int or a decimal in a bunch of places in my code I created an extension method which will handle the dirty work.

This pattern is something I find myself coming back to constantly.  Hopefully you'll find some use for it.