October 10, 2003 08:12 am

Generic Methods

Before I turned on the television, I added some preliminary support for "real" generic methods, for instance:

class Stack<T> { public static void Hello (T t, S s, U u) { U v = u; } }

The runtime part was really easy and straightforward so far. There's just one small problem: TypeBuilder.DefineMethod() takes a Type[] array of the method's parameter types - so we need to create the generic parameters before we have the MethodBuilder. To keep things simple, I just added an index field to MonoReflectionGenericParam and added support for it to mono_reflection_define_generic_parameter(). There's now an overloaded version of TypeBuilder.DefineGenericParameter() which takes an index argument.

Adding support to gmcs was a bit more difficult as I already mentioned in my last blog. I added a new GenericMethod class (derives from DeclSpace) which is created just before calling new Method (...). We add the type parameters to the GenericMethod and use it as DeclSpace to lookup parameters and local variables.

There's a new tests/gen-15.cs example which can now be compiled by gmcs.

We cannot call generic methods yet, I need to add support to the runtime, class libs and gmcs for this first.

Posted by martin at October 10, 2003 08:12 am.