Take for example some kind of factory method (or any method that has a type as a parameter, and returns an instance of that type):
SomeType instance = (SomeType)Factory.CreateInstance(typeof(SomeType));
Using generics can cut right through:
SomeType instance = Factory.CreateInstance<SomeType>();
It's particularly noticable in VB.Net (because it has such munted cast syntax in the first place), but the result is normally a lot more legible. Unfortunately the framework is full of missed opportunities to clean up:
thing = DirectCast(Enum.Parse(GetType(SomeType), someValue), SomeType)
could become
thing = Enum.Parse(Of SomeType)(SomeValue)
That's got to be better, right?
No comments:
Post a Comment