I am working on a problem where I want to replace a method on a class with
a new method.

I want to transform this:

public class Foo {
    public int Bar(){
        return 0;
    }
};

into this:

public class Foo {
    public int _Call_Bar(string a, string b){
        return 0;
    }

    public int Bar(string a, string b){
        try {
            //do some preprocessing
            return _Call_Bar(a, b);
        } finally {
            //post processing
        }
    }
}

I have it mostly working.  However, when Foo has a generic parameter (IE,
public class Foo<T>) then the generated IL looks to be incorrect.

I end up with a call to

    L_000d: call instance int32 Demo.Foo`1::_Call_Bar(!T, !T)

However, when I try to use this new type in an assembly it fails with a
type load exception (PEVerify says the assembly is verified).

I tried to look at the compiler generated IL as if I had do the
transformation manually, and it ends up with a slightly different call


    L_000d: call instance int32 Demo.Foo`1<!T>::_Call_Bar(!T, !T)


It looks like the call doesn't know anything about the generic type of Foo?

How can I say that the call to _Call_Bar is for type Foo<T>?

Thanks,

JP

-- 
--
mono-cecil

Reply via email to