From: hammett <ha...@uo...> - 2004-10-27 14:16:15
|
Hello Deyan, > I have been playing with the new IInvocation, and I noticed that both > properties IInvocation.Proxy and IInvocation.InvocationTarget are the > same. > What's there meaning, btw? The target means: when I invoke proceed, which object will receive the execution; and the proxy is the proxy itself. When proxying a class, both values will be the same. When intercepting interfaces (using ProxyGenerator.CreateProxy) then the values will be different. > What is bothering me is that there is no way to substitute the real object > in the PreProcess method of my Interceptor, which is a part of the object > lazy-loading process... Well, this is easy to fix. We can make the InvocationTarget writable, but then the Proceed in the SameClassInvocation must be changed to something like: public override object Proceed(params object[] args) { object value = null; if (TargetInvocation == Proxy) { value = call.Call( args ); } else { value = Method.Invoke( InvocationTarget, args ); } return value; } Because there is no wasy to use the delegate to invoke the method somewhere else. I could even generate two different delegates: one to invoke the base() and one to invoke anotherobject() but in this case I must know the Type of the anotherobject during the object generation, something like: private void callback_1(int x) { base.DoSomething(x); } private void otherobjectcallback(int x) { // This is generated by // gen.Emit( OpCodes.callvirt, typeof(target).GetMethod("DoSomething", new type[] { typeof(int) } ); target.DoSomething(x); } > I see that NHibernate also has this problem, as it > retrieves the real object from the db and delegates (using runtime > reflection) the calls to it. I would like to execute the methods on the > real > object without runtime reflection, which means that either I can substitte > the real object (perhaps this is the IInvocation.InvocationTarget which > has > only a getter) - this I think is not possible, or populate the properties > of > the proxy from the db at runtime, and then take advantage of the Dynamic > Proxy new calling infrastructure. Can you expose your code somewhere so we can see exactly the problem? It will be easier to picture the solution... -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett |