Re[mono-cecil] solving generic method parameters

358 views
Skip to first unread message

Vagaus

unread,
Feb 10, 2010, 1:24:32 PM2/10/10
to mono-...@googlegroups.com

Hi.

I have a reference to the following parameter (param):

param.ParameterType
{System.Collections.Generic.IEnumerable`1<!0>}
{Mono.Cecil.GenericInstanceType}

that is defined int the following method (param.Method)

{ System.Void
System.Collections.Generic.List`1<System.String>::.ctor(System.Collections.Generic.IEnumerable`1<!0>)}

The problem is: how to get a "closed" parameter (One with !0 replaced by the
actual type System.String) ?

I have tried param.ParameterType().Resolve() but this gave me back
System.Collections.Generic.IEnumerable`1.

Best

Adriano
--
View this message in context: http://old.nabble.com/Resolving-generic-method-parameters-tp27535759p27535759.html
Sent from the Mono - Cecil mailing list archive at Nabble.com.

Jb Evain

unread,
Sep 28, 2012, 3:19:46 AM9/28/12
to mono-...@googlegroups.com
Hey,

What is usually done is to create a mapping for the current generic
context between the generic parameters and the generic arguments.
This way you are able to “resolve” (not in the Cecil .Resolve() sense)
a generic parameter into its argument (that may or not be a generic
parameter).

There's nothing that Cecil exposes, nor a recommended/preferred way, to do that.

Best,

Jb

On Fri, Sep 28, 2012 at 9:03 AM, John Marshall
<john.m....@gmail.com> wrote:
> I'm having the same issue. It looks like GenericParameters like !!0 can be
> resolved to actual TypeDefinitions by using the GenericArguments which
> specify <int,int> for instance, but is there a proper way to do this? My
> current implementation works, but feels hackish because it has to
> recursively iterate a type's argument's looking for GenericParameters to
> replace with actual TypeDefinitions.
>
> Thanks, John
>
> www.codeperspective.com :)
>
> --
> --
> mono-cecil

John Marshall

unread,
Sep 28, 2012, 3:29:13 AM9/28/12
to mono-...@googlegroups.com
Ok thanks, good to know that I'm not re-implementing something. For what I'm doing it's pretty useful because I'm taking those generic functions and creating wrappers for them in some cases, and in others I have to know whether to box return types or not, with the correct type declaration for the box operation of course. If I have some kind of cleaned up solution for this in the future, would you want me to submit a pull request to add this to cecil rocks or something? 

Thanks again, John
Reply all
Reply to author
Forward
0 new messages