[Mono-list] Extending generic methods

Jb Evain jb at nurv.fr
Sun Sep 28 13:14:49 EDT 2008


Hey,

On 9/28/08, Chris Howie <cdhowie at gmail.com> wrote:
> On Sun, Sep 28, 2008 at 11:52 AM, DraconisBG <draconisbg at yahoo.com> wrote:
>  > I got a task where I have to modify Mono/GMCS in order to make the following
>  > possible:
>  >
>  > ------------------------------------------------
>  > public void GenericMethod<T> (...) {...}
>  >
>  > ...
>  >
>  > System.Type typ = <expression that evaluates to a type>;
>  > GenericMethod<typ> (...);
>  >
>  > ------------------------------------------------
>
>
> Uhm, this is already possible and working, and has been for (IIRC)
>  several releases.

Not it's not. Here `typ' is a System.Type instance, and thus, can't be
used as a generic argument for the GenericMethod.

But to me, it seems that here, the whole JIT/gmcs modification is a
little bit too much. Especially as you can use something like a linq
expression tree to create a dynamic method that will call the generic
method with the dynamically retrieved type.

You won't lose too much of performances because of the DynamicMethod
used to compile the expression tree.

-- 
Jb Evain  <jb at nurv.fr>


More information about the Mono-list mailing list