Featured post
Implementing Generic Type Inference in C# reflectively -
i need generic type inference scripting language implementation , wondering if missing straightforward approach. moment let me ask type structure , ignore bounds. illustrate, here nested example:
t foo<t>( list<list<list<t>>> ) {...}
now want test if can pass argument bar of type:
list<list<list<string>>>
to method , later use makegenericmethod() discovered param type reify , invoke it.
from can tell, if manage construct open generic type equivalent foo argument (i.e. list<list<list<t>>>
), not test isassignable(). i'm not sure if there trick checking assignability of open generic types or if it's not supported. guess if have can directly.
on reification - looks i'm going have recursively crawl through types find argument type matches location of type parameter , substitution... had been hoping might able somehow construct invocable method argument type more directly, i'm not seeing how this.
any advice who's gone through madness appreciated :)
thanks, pat niemeyer
so, believe have implemented going on assumption have reify types assignability comparison. near can tell there not way extract base type generic type in order perform assignment checks yourself. ended doing using getgenericarguments traverse method parameter type , argument type in parallel, performing sanity checks @ each step (number of generic params match, etc.) , once finding "naked" generic type param, noting corresponding (inferred) type in argument. can determine you've found type param using isgenericparameter. then, weirdly, have save types aside , use them instantiate method passing them in particular order makegenericmethod. order provided property on type itself, genericparameterposition, (again, weird) simple orderby sorts them out. after of normal rules seem apply.
-pat
- Get link
- X
- Other Apps
Comments
Post a Comment