From: Jon Skeet [C# MVP] on
Anthony Paul <anthonypaulo(a)gmail.com> wrote:
> In reply to your post on the other duplicate thread (I had no idea it
> was posted twice) as to why I didn't pass the generic type via the
> generic method call :
>
> public void DoSomething<T>(object o)
>
> I can't do this because it mean making an assumption that object "o"
> is of a certain generic type when that may not be the case. What if
> it's just a regular old int? or a string? It could be an IMinMax<T> in
> which case the T would come in handy, but what if it was a... let's
> say, ISeries<T, U, V> ??

Then your cast on the first line of DoSomething is going to throw an
exception immediately.

--
Jon Skeet - <skeet(a)pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
From: Anthony Paul on
Yes... that's my point, it won't work. So my question is... how does
one go about doing it?

On Jul 19, 4:32 pm, Jon Skeet [C# MVP] <sk...(a)pobox.com> wrote:
> Anthony Paul <anthonypa...(a)gmail.com> wrote:
> > In reply to your post on the other duplicate thread (I had no idea it
> > was posted twice) as to why I didn't pass the generic type via the
> > generic method call :
>
> > public void DoSomething<T>(object o)
>
> > I can't do this because it mean making an assumption that object "o"
> > is of a certain generic type when that may not be the case. What if
> > it's just a regular old int? or a string? It could be an IMinMax<T> in
> > which case the T would come in handy, but what if it was a... let's
> > say, ISeries<T, U, V> ??
>
> Then your cast on the first line of DoSomething is going to throw an
> exception immediately.
>
> --
> Jon Skeet - <sk...(a)pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too


From: Jon Skeet [C# MVP] on
Anthony Paul <anthonypaulo(a)gmail.com> wrote:
> Yes... that's my point, it won't work. So my question is... how does
> one go about doing it?

Doing what, exactly? You can't pretend that something implements an
interface if it doesn't.

I originally thought that your problem was not knowing what kind of
IMinMax<T> to cast to (i.e. what to use as T). If you're wanting to use
something which *isn't* an IMinMax<T> as if it is, that's a completely
different question.

--
Jon Skeet - <skeet(a)pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too