He************* @googlemail.com wrote:
Although it does seem a wee bit complicated... I guess I don't
understand enough about .NET to comprehend why I would need to use
reflection for (what seems to me to be) such a trivial exercise.
Because you're trying to fit a round peg into a square hole. The Type class
is for passing type information at runtime; generics are for passing type
information at compile time.
Think of generics as a way to insert a ____ blank in a sentence -- you have
to fill it in *before* you have a complete sentence you can read aloud.
Using a Type parameter, on the other hand, is like saying "Take any type,
let's call it T. Given this T, I want to do the following...". Here you
always use complete sentences, but it's a much more roundabout way of doing
things and fundamentally incompatible with the placeholder approach. The
compiler, of course, demands that your sentences always make sense in every
circumstance, even though they might not be true at runtime.
If you really want this you could implement it the other way around: have
the method that takes a Type do the work and have the generic implementation
delegate to it by means of typeof. That's the "right way around", and the
solution there really is trivial. Of course, the method that uses Type may
be anything but.
--
J.
http://symbolsprose.blogspot.com