Hi there,

I'm trying to emit calls to the '!=' operator of types that have one.

So, I defined the following method:

    public MethodReference GetInequalityOperator(TypeReference
typeReference)
    {
        // AssemblyResolver from Mono Linker
        AssemblyResolver resolver = new AssemblyResolver();
        TypeDefinition definition = resolver.Resolve(typeReference);
        return definition.Methods.GetMethod("op_Inequality",
                                            new TypeReference[]
{ typeReference, typeReference });
    }

which allows me to get a MethodReference representing the operator I
need to call, from a type reference.

But it seems the emitted code is invalid, and I get this error with
ildasm on the call line:

IL_0007:  call        [ERROR: INVALID TOKEN 0x06000145]

If I use the following method to get the MethodReference, it works
fine :

    public MethodReference GetInequalityOperator(TypeReference
typeReference)
    {
        MethodReference methodReference = null;
        Type type =
Type.GetType(typeReference.GetOriginalType().FullName);
        MethodInfo info = type.GetMethod("op_Inequality", new Type[]
{ type, type });
        if (info != null)
        {
            methodReference = this.assembly.MainModule.Import(info);
        }
        return methodReference;
    }

Any idea ? I'm pretty sure I missed something (big) here.

Thank you,

Romain

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to