[Mono-list] Extending generic methods

DraconisBG draconisbg at yahoo.com
Sun Sep 28 11:52:46 EDT 2008


Hello,

Sorry if I send this to the wrong list, please direct me where I should send
it.

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> (...);

------------------------------------------------

In other words, type arguments can be defined in runtime for generic method
instantiations (calls). The instantiation's type argument won't be
System.Type, but rather the type represented by the particular System.Type.

Using Reflection is not allowed, for perf reasons (so I can't just generate
IL code on the fly). Unfortunately, the signature of the gen.method
instantiation is fixed in the IL code, so it seems that the modification of
the JIT compiler will be needed.

However, if I just change the JIT to resolve System.Type type arguments, it
will result in problems (backward compatibility, and cases where we really
want System.Type as type argument).

So I guess something like this would work:
1. Modification of gmcs (Expression resolving etc.), no problem here
2. Modifying JIT to be able to resolve System.Type type arguments *when*
needed
3. Modification of gmcs to emit code into the app which *informs* JIT before
such a call, so the JIT will now that in *this* case, System.Type type
argument must be substitured with the actual type.

However, I'm not sure if this is a good or even a working solution (I can't
think of an easier solution withotu generating IL code on-the-fly), and even
if it's workable, what are the key moments of the implementation.

Any thoughts/help would be greatly appreciated! 
-- 
View this message in context: http://www.nabble.com/Extending-generic-methods-tp19712662p19712662.html
Sent from the Mono - General mailing list archive at Nabble.com.



More information about the Mono-list mailing list