castleproject / Core

Castle Core, including Castle DynamicProxy, Logging Services and DictionaryAdapter
http://www.castleproject.org/
Other
2.2k stars 467 forks source link

CreateInterfaceProxyWithoutTarget and BaseTypeForInterfaceProxy-member #672

Open WolfgangKluge opened 10 months ago

WolfgangKluge commented 10 months ago

I want to create a proxy from an interface where some methods are already defined by a base class.

E.g.

public abstract class Base {
    public void Test() {}
}
public interface I {
    void Test();
    int Value { get; set; }
}

My proxy should look like that (without Test).

public class Proxy : Base, I {
    public int Value { get; set; }
}

But the proxy will always have it's own method Test (no matter what the return value from an IProxyGenerationHook is).

Then I tried to intercept this method as well and pass the arguments to the base class, but I'm not able to do that in an easy way (I think from here it's quite the same as #647).

So my question is: is there a way to filter the methods that have to be generated by the proxy builder (at least on those methods that are already defined by BaseTypeForInterfaceProxy)?


Another solution would be to modify the generated proxy code to something like

public class Proxy : Base, I {
    public new void Test() {
        base.Test();
    }
    public int Value { get; set; }
}

whenever Test should not be intercepted as of IProxyGenerationHook and there is such a method in one of the base types.

Is there a way to hook into the generation process (with more possibilities than now)?

stakx commented 1 week ago

Have you tried either declaring Base.Test virtual, or letting your Base class implement I?

Then I tried to intercept this method as well and pass the arguments to the base class, but I'm not able to do that in an easy way

How did you attempt to do this, and in what way was it not easy?