Tagged with generics
To(): a handy way to convert strings to other types
The int.parse() method is one I use a lot in ASP.NET so I wrote a handy extension method called To using generic return types and a little reflection that makes converting all these string values to another type incredibly simple.Published in .NET on Monday, February 23rd, 2009
Generic method return types
Generics aren't just great for creating lists, they can also be used to return strongly typed information from a method. This example shows how to use a generic return type to parse any type of strongly typed primitive from a string.Published in .NET on Monday, May 5th, 2008
One more thing to love about .NET generics: events with custom event args
Lists are a killer app for generics in .NET 2.0 but one of my favourite uses that gets less attention is declaring event handlers without having to create a custom delegeate. Imagine a situation where you want to pass a piece of custom information to the event handler so it can decide whether to cancel [...]Published in .NET on Saturday, April 26th, 2008
What type are you really?
I had an interesting problem the other day. I had a situation where someone could pass a type to my method which could be potentially be a nullable type and I needed to know what the real type actually was. It turned out to be pretty easy to find out. The Type type has a [...]Published in .NET on Friday, May 4th, 2007






