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

Reply via email to