Okay, I see the problem. Nonetheless, I have to make this work somehow.
I'm currently trying something like:

public static MethodReference ResolveTransform(this MethodReference
methodRef, Func<TypeReference, TypeReference> genericArgTransformer,
Func<MethodDefinition, MethodDefinition> resolvedMethodTransformer) { ... }

And something similar for TypeReference. The idea is that I cannot have a
TypeDefinition while I have generic arguments, so lets split the task:
genericArgTransformer is called for each and every generic arguments there
is in the TypeReference (or MethodReference), which executes its task (i.e.
moving the types to the exe file), and somewhere, deep within there also
must be a MethodDefinition (below all generic arguments), which is also
processed seperately.

In theory this should work (at least I couldn't yet find out why shouldn't
it), though I have to rewrite the code in many parts.

Thanks for your help anyway!

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

> On Mon, Jul 5, 2010 at 3:10 PM, Gábor Kozár <[email protected]> wrote:
> > It doesn't matter if I have 3 methods or 1; the point is that I need
> this:
> >
> > TypeDefinition ResolvePreserve(TypeReference)
>
> Indeed proper design doesn't matter if you want something that can't
> possibly exist.
>
> > And a GenericInstanceMethod cannot be cast to TypeDefinition, only
> > TypeReference, but I don't need a TypeReference. I need a TypeDefinition.
> > What I have seen so far lets me think that it is impossible (by design)
> for
> > a TypeDefinition (or any Definition) to have generic arguments. Or can it
> be
> > solved?
>
> ResolvePreserve can only return a TypeReference because it's the root
> of all types. Let's try to make it simple for you.
> In your assembly, you have a TypeReference to List<string>.
>
> What you actually have is:
>
> GenericInstanceType
>  ElementType: TypeReference(List`1)
>  GenericArguments: TypeReference(String)
>
> Now with ResolvePreserved you want:
>
> GenericInstanceType
>  ElementType: TypeDefinition(List`1)
>  GenericArguments: TypeDefinition(String)
>
> And the hierarchy of GenericInstanceType is: TypeReference ->
> TypeSpecification -> GenericInstanceType.
>
> So ResolvePreserve needs to return a TypeReference for all
> TypeSpecifications, such as arrays. And it's ok, you can write:
>
> TypeReference ResolvePreserved (this TypeReference self);
>
> TypeReference resolved = type.ResolvePreserved ();
> if (resolved.IsDefinition) {
>    TypeDefinition definition = (TypeDefinition) resolved;
>    // ...
> }
>
> --
> Jb Evain  <[email protected]>
>
> --
> --
> mono-cecil
>

-- 
--
mono-cecil

Reply via email to