From: Mike D. <mik...@gm...> - 2004-10-22 19:12:46
|
Hi guys. Before I ask my question I just want to say good job on the work so far! I'm working on getting Dynamic Proxying working with NHibernate and so far so good. One of the things I'm running into is that for a Class to be proxyable the ctor has to be public and the properties/methods have to be virtual and public. The virtual requirement makes sense - can't override a non virtual method. Is there any reason that the constructor and properties/methods with an access level of protected can't be proxied? It looks like a relatively small code change in BaseCodeGenerator but since it looked small there has to be something else to it :) Thanks and keep up the good work! Mike |
From: hammett <ha...@uo...> - 2004-10-22 19:35:04
|
Hello Mike, We're currently moving our codebase from ASF, so expect a different namespace. I antecipate my apologies! :-) Well, the public constructor isnt a problem, really. I think the requirement came from our lazyness. protected ConstructorBuilder GenerateConstructor() { ConstructorBuilder consBuilder = m_typeBuilder.DefineConstructor( MethodAttributes.Public, CallingConventions.Standard, new Type[] {typeof (IInvocationHandler)}); ILGenerator ilGenerator = consBuilder.GetILGenerator(); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Call, m_baseType.GetConstructor(new Type[0])); ilGenerator.Emit(OpCodes.Ldarg_0); ilGenerator.Emit(OpCodes.Ldarg_1); ilGenerator.Emit(OpCodes.Stfld, m_handlerField); ilGenerator.Emit(OpCodes.Ret); return consBuilder; } I'll change the baseType.GetConstructor to be smarter. About the protected methods, I'd better write a test case before I answer that, but should not be a problem.... -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett ----- Original Message ----- From: "Mike Doerfler" <mik...@gm...> To: <asp...@li...> Sent: Friday, October 22, 2004 12:12 PM Subject: [Aspectsharp-users] DynamicProxy > Hi guys. Before I ask my question I just want to say good job on the > work so far! I'm working on getting Dynamic Proxying working with > NHibernate and so far so good. > > One of the things I'm running into is that for a Class to be proxyable > the ctor has to be public and the properties/methods have to be > virtual and public. The virtual requirement makes sense - can't > override a non virtual method. Is there any reason that the > constructor and properties/methods with an access level of protected > can't be proxied? It looks like a relatively small code change in > BaseCodeGenerator but since it looked small there has to be something > else to it :) > > Thanks and keep up the good work! > > Mike > > |
From: hammett <ha...@uo...> - 2004-10-22 20:16:11
|
Ok, both fixed. The protected/internal/interal protected were bugs.. :-( I'm working on the serialization issues pointed by Henry and a small release should be available on Aspect# CVS tonight. But although its possible to generate stubs for non-public methods, they need to be accessed with a proxy pointer (the this reference is not proxied). Cglib handles is gracefully - only God knows how - but I think it will be amazingly difficult to tackle. Ideas? -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett ----- Original Message ----- From: "hammett" <ha...@uo...> To: <asp...@li...> Sent: Friday, October 22, 2004 4:34 PM Subject: Re: [Aspectsharp-users] DynamicProxy > Hello Mike, > > We're currently moving our codebase from ASF, so expect a different > namespace. I antecipate my apologies! :-) > > Well, the public constructor isnt a problem, really. I think the > requirement came from our lazyness. > > protected ConstructorBuilder GenerateConstructor() > { > ConstructorBuilder consBuilder = m_typeBuilder.DefineConstructor( > MethodAttributes.Public, > CallingConventions.Standard, > new Type[] {typeof (IInvocationHandler)}); > > ILGenerator ilGenerator = consBuilder.GetILGenerator(); > ilGenerator.Emit(OpCodes.Ldarg_0); > ilGenerator.Emit(OpCodes.Call, m_baseType.GetConstructor(new Type[0])); > ilGenerator.Emit(OpCodes.Ldarg_0); > ilGenerator.Emit(OpCodes.Ldarg_1); > ilGenerator.Emit(OpCodes.Stfld, m_handlerField); > ilGenerator.Emit(OpCodes.Ret); > > return consBuilder; > } > > I'll change the baseType.GetConstructor to be smarter. > About the protected methods, I'd better write a test case before I answer > that, but should not be a problem.... |
From: Mike D. <mik...@gm...> - 2004-10-22 21:07:57
|
Hi hammet. That's quick. I'll keep an eye out for any announcements about new code locations :) I'm coming at this from a completely naive perspective. I thought the DynamicProxy was just building a subclass of the class we are proxying. So I don't understand why "this.SomeProperty" would refer to the base class instead of the proxy class if "SomeProperty" was virtual and public/protected. I'll have to look at that some more. Thanks again! Mike On Fri, 22 Oct 2004 17:15:51 -0700, hammett <ha...@uo...> wrote: > Ok, both fixed. The protected/internal/interal protected were bugs.. :-( > I'm working on the serialization issues pointed by Henry and a small release > should be available on Aspect# CVS tonight. > > But although its possible to generate stubs for non-public methods, they > need to be accessed with a proxy pointer (the this reference is not > proxied). > Cglib handles is gracefully - only God knows how - but I think it will be > amazingly difficult to tackle. Ideas? > > > > -- > Cheers, > hammett > http://www.digitalcraftsmen.com.br/~hammett > > ----- Original Message ----- > From: "hammett" <ha...@uo...> > To: <asp...@li...> > Sent: Friday, October 22, 2004 4:34 PM > Subject: Re: [Aspectsharp-users] DynamicProxy > > > Hello Mike, > > > > We're currently moving our codebase from ASF, so expect a different > > namespace. I antecipate my apologies! :-) > > > > Well, the public constructor isnt a problem, really. I think the > > requirement came from our lazyness. > > > > protected ConstructorBuilder GenerateConstructor() > > { > > ConstructorBuilder consBuilder = m_typeBuilder.DefineConstructor( > > MethodAttributes.Public, > > CallingConventions.Standard, > > new Type[] {typeof (IInvocationHandler)}); > > > > ILGenerator ilGenerator = consBuilder.GetILGenerator(); > > ilGenerator.Emit(OpCodes.Ldarg_0); > > ilGenerator.Emit(OpCodes.Call, m_baseType.GetConstructor(new Type[0])); > > ilGenerator.Emit(OpCodes.Ldarg_0); > > ilGenerator.Emit(OpCodes.Ldarg_1); > > ilGenerator.Emit(OpCodes.Stfld, m_handlerField); > > ilGenerator.Emit(OpCodes.Ret); > > > > return consBuilder; > > } > > > > I'll change the baseType.GetConstructor to be smarter. > > About the protected methods, I'd better write a test case before I answer > > that, but should not be a problem.... > > ------------------------------------------------------- > This SF.net email is sponsored by: IT Product Guide on ITManagersJournal > Use IT products in your business? Tell us what you think of them. Give us > Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more > http://productguide.itmanagersjournal.com/guidepromo.tmpl > _______________________________________________ > Aspectsharp-users mailing list > Asp...@li... > https://lists.sourceforge.net/lists/listinfo/aspectsharp-users > |
From: hammett <ha...@uo...> - 2004-10-22 21:16:18
|
Hiya, > I'm coming at this from a completely naive perspective. I thought the > DynamicProxy was just building a subclass of the class we are > proxying. Yes, that's exactly what it does. > So I don't understand why "this.SomeProperty" would refer > to the base class instead of the proxy class if "SomeProperty" was > virtual and public/protected. I'll have to look at that some more. You mean: callvirt will be used. It should, good point, so I wonder why my test case failed. :-( Meanwhile we're working on a non-public repository. Let me know if you want to have access and I send you (privately) login and password. -- Cheers, hammett http://www.digitalcraftsmen.com.br/~hammett |