I had a similar idea myself. Thank you!

2010/7/3 Jb Evain <[email protected]>

> Hey,
>
> On Sat, Jul 3, 2010 at 8:39 PM, Gábor Kozár <[email protected]> wrote:
> > When I have a MethodReference or TypeReference representing a generic
> method
> > call / object instance, calling Resolve() seems to eliminate the generic
> > arguments, resulting in invalid references in the CIL code. Is this
> > intentional?
>
> Yes. Resolve returns the corresponding *Definition. There's currently
> nothing builtin that does a Resolve + rebuilding of a type spec.
>
> > The problem is that I need to call Resolve(), then manipulate the
> resulting
> > definition object, and I also have to preserve (and manipulate) the
> generic
> > arguments (if any).
> > Any hints?
>
> Just implement it on top of Resolve, something like:
>
> public static TypeReference ResolvePreserve (this TypeReference self)
> {
>        if (self.IsGenericInstance) {
>                var previous_instance = (GenericInstanceType) self;
>                var instance = new GenericInstanceType
> (previous_instance.ElementType.ResolvePreserve ());
>                foreach (var argument in previous_instance.GenericArguments)
>                        instance.GenericArguments.Add
> (argument.ResolvePreserve ());
>        }
>
>        if (self.IsArray) {
>                // ..
>        }
>
>        if (self.IsByReference) {
>                //
>        }
>
>        return self.Resolve ();
> }
>
> --
> Jb Evain  <[email protected]>
>
> --
> --
> mono-cecil

-- 
--
mono-cecil

Reply via email to