I need to do some generic type inference for a scripting language implementation and I am wondering if I am missing some straightforward approach. For the moment let me just ask about type structure and ignore bounds. To illustrate, here is a deeply nested example:
T foo<T>( List<List<List<T>>> ) {...}
Now I want to test if I can pass an argument bar of type:
List<List<List<string>>>
to that method and later use MakeGenericMethod() with the discovered param type to reify and invoke it.
From what I can tell, even if I manage to construct an open generic type equivalent to the foo argument (i.e. List<List<List<T>>>
), it will not test with isAssignable(). I'm not sure if there is some trick to checking the assignability of open generic types or if it's simply not supported. I guess if I have to I can do this directly.
On the reification - It looks like I'm going to have to recursively crawl through the types to find the argument type that matches the location of the type parameter and then do the substitution... I had been hoping that I might be able to somehow construct the invocable method from the argument type more directly, but I'm not seeing how to do this.
Any advice from someone who's already gone through this madness would be appreciated :)
thanks, Pat Niemeyer