From: Kevin W. <kev...@us...> - 2004-12-31 22:08:20
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Proxy In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6624 Modified Files: CastleCustomProxyGenerator.cs CastleLazyInitializer.cs CastleProxyGenerator.cs Log Message: fixing xml comments and letting ReSharper do reformatting Index: CastleLazyInitializer.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Proxy/CastleLazyInitializer.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CastleLazyInitializer.cs 16 Dec 2004 21:51:48 -0000 1.2 --- CastleLazyInitializer.cs 31 Dec 2004 22:08:10 -0000 1.3 *************** *** 1,7 **** using System; using System.Reflection; - using Castle.DynamicProxy; ! using NHibernate.Engine; --- 1,6 ---- using System; using System.Reflection; using Castle.DynamicProxy; ! using log4net; using NHibernate.Engine; *************** *** 12,22 **** /// </summary> [Serializable] ! [CLSCompliant(false)] ! public class CastleLazyInitializer : LazyInitializer, Castle.DynamicProxy.IInterceptor//, ISerializable { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger( typeof(CastleLazyInitializer) ); ! private System.Type _concreteProxy; ! private System.Type[] _interfaces; /// <summary> --- 11,21 ---- /// </summary> [Serializable] ! [CLSCompliant( false )] ! public class CastleLazyInitializer : LazyInitializer, Castle.DynamicProxy.IInterceptor //, ISerializable { ! private static readonly ILog log = LogManager.GetLogger( typeof( CastleLazyInitializer ) ); ! private System.Type _concreteProxy; // not used !?! ! private System.Type[ ] _interfaces; // not used !?! /// <summary> *************** *** 29,34 **** /// <param name="identifierPropertyInfo">The PropertyInfo for the <id> property.</param> /// <param name="session">The ISession this Proxy is in.</param> ! internal CastleLazyInitializer(System.Type persistentClass, System.Type concreteProxy, System.Type[] interfaces, object id, PropertyInfo identifierPropertyInfo, ISessionImplementor session) ! : base (persistentClass, id, identifierPropertyInfo, session) { _concreteProxy = concreteProxy; --- 28,33 ---- /// <param name="identifierPropertyInfo">The PropertyInfo for the <id> property.</param> /// <param name="session">The ISession this Proxy is in.</param> ! internal CastleLazyInitializer( System.Type persistentClass, System.Type concreteProxy, System.Type[ ] interfaces, object id, PropertyInfo identifierPropertyInfo, ISessionImplementor session ) ! : base( persistentClass, id, identifierPropertyInfo, session ) { _concreteProxy = concreteProxy; *************** *** 45,62 **** /// <param name="args">The parameters for the Method/Property</param> /// <returns>The result just like the actual object was called.</returns> ! public object Intercept(IInvocation invocation, params object[] args) { // let the generic LazyInitializer figure out if this can be handled // with the proxy or if the real class needs to be initialized ! object result = base.Invoke( invocation.Method, args); // the base LazyInitializer could not handle it so we need to Invoke // the method/property against the real class ! if( result==InvokeImplementation ) { invocation.InvocationTarget = GetImplementation(); return invocation.Proceed( args ); } ! else { return result; --- 44,61 ---- /// <param name="args">The parameters for the Method/Property</param> /// <returns>The result just like the actual object was called.</returns> ! public object Intercept( IInvocation invocation, params object[ ] args ) { // let the generic LazyInitializer figure out if this can be handled // with the proxy or if the real class needs to be initialized ! object result = base.Invoke( invocation.Method, args ); // the base LazyInitializer could not handle it so we need to Invoke // the method/property against the real class ! if( result == InvokeImplementation ) { invocation.InvocationTarget = GetImplementation(); return invocation.Proceed( args ); } ! else { return result; *************** *** 65,69 **** #endregion - } ! } --- 64,67 ---- #endregion } ! } \ No newline at end of file Index: CastleProxyGenerator.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Proxy/CastleProxyGenerator.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CastleProxyGenerator.cs 16 Dec 2004 21:51:48 -0000 1.2 --- CastleProxyGenerator.cs 31 Dec 2004 22:08:10 -0000 1.3 *************** *** 2,11 **** using System.Collections; using System.Reflection; - using System.Reflection.Emit; - using Castle.DynamicProxy; - using Castle.DynamicProxy.Builder; using Castle.DynamicProxy.Builder.CodeGenerators; ! using NHibernate.Engine; --- 2,8 ---- using System.Collections; using System.Reflection; using Castle.DynamicProxy; using Castle.DynamicProxy.Builder.CodeGenerators; ! using log4net; using NHibernate.Engine; *************** *** 17,21 **** public class CastleProxyGenerator : IProxyGenerator { ! private static readonly log4net.ILog log = log4net.LogManager.GetLogger( typeof(CastleProxyGenerator) ); // key = mapped type --- 14,18 ---- public class CastleProxyGenerator : IProxyGenerator { ! private static readonly ILog log = LogManager.GetLogger( typeof( CastleProxyGenerator ) ); // key = mapped type *************** *** 37,41 **** // the EnhanceTypeDelegate will add custom code gen that DynamicProxy does not provide // by default. ! _context = new GeneratorContext( );// new EnhanceTypeDelegate( EnhanceInterfaceType ), null ); } --- 34,38 ---- // the EnhanceTypeDelegate will add custom code gen that DynamicProxy does not provide // by default. ! _context = new GeneratorContext(); // new EnhanceTypeDelegate( EnhanceInterfaceType ), null ); } *************** *** 49,59 **** /// <param name="identifierPropertyInfo">The PropertyInfo to get/set the Id.</param> /// <param name="id">The value for the Id.</param> /// <param name="session">The Session the proxy is in.</param> /// <returns>A fully built <c>INHibernateProxy</c>.</returns> ! public INHibernateProxy GetProxy(System.Type persistentClass, System.Type concreteProxy, System.Type[] interfaces, PropertyInfo identifierPropertyInfo, object id, ISessionImplementor session) { object generatedProxy = null; ! try ! { CastleLazyInitializer initializer = new CastleLazyInitializer( persistentClass, concreteProxy, interfaces, id, identifierPropertyInfo, session ); System.Type proxyType = null; --- 46,57 ---- /// <param name="identifierPropertyInfo">The PropertyInfo to get/set the Id.</param> /// <param name="id">The value for the Id.</param> + /// <param name="concreteProxy"></param> /// <param name="session">The Session the proxy is in.</param> /// <returns>A fully built <c>INHibernateProxy</c>.</returns> ! public INHibernateProxy GetProxy( System.Type persistentClass, System.Type concreteProxy, System.Type[ ] interfaces, PropertyInfo identifierPropertyInfo, object id, ISessionImplementor session ) { object generatedProxy = null; ! try ! { CastleLazyInitializer initializer = new CastleLazyInitializer( persistentClass, concreteProxy, interfaces, id, identifierPropertyInfo, session ); System.Type proxyType = null; *************** *** 63,67 **** // to define the same type twice in it. So nh needs to keep a cache of the proxy types that have // already been generated. ! lock( cachedProxyTypes.SyncRoot ) { proxyType = cachedProxyTypes[ concreteProxy ] as System.Type; --- 61,65 ---- // to define the same type twice in it. So nh needs to keep a cache of the proxy types that have // already been generated. ! lock( cachedProxyTypes.SyncRoot ) { proxyType = cachedProxyTypes[ concreteProxy ] as System.Type; *************** *** 72,87 **** if( concreteProxy.IsInterface ) { ! if( proxyType==null ) { //TODO: figure out if this is necessary because the concreteProxy is // already included in the interfaces array... ! System.Type[] temp = new System.Type[ interfaces.Length + 1 ]; interfaces.CopyTo( temp, 0 ); temp[ interfaces.Length ] = concreteProxy; //persistentClass; interfaces = temp; ! InterfaceProxyGenerator _interfaceGenerator = new InterfaceProxyGenerator( _scope, _context ); proxyType = _interfaceGenerator.GenerateCode( interfaces ); ! cachedProxyTypes[ concreteProxy ] = proxyType; } --- 70,85 ---- if( concreteProxy.IsInterface ) { ! if( proxyType == null ) { //TODO: figure out if this is necessary because the concreteProxy is // already included in the interfaces array... ! System.Type[ ] temp = new System.Type[interfaces.Length + 1]; interfaces.CopyTo( temp, 0 ); temp[ interfaces.Length ] = concreteProxy; //persistentClass; interfaces = temp; ! InterfaceProxyGenerator _interfaceGenerator = new InterfaceProxyGenerator( _scope, _context ); proxyType = _interfaceGenerator.GenerateCode( interfaces ); ! cachedProxyTypes[ concreteProxy ] = proxyType; } *************** *** 90,117 **** // hack with new object() because an interface proxy is expecting an actual target instance - we // don't have that yet and don't want to create it until it is actually needed. ! generatedProxy = Activator.CreateInstance( proxyType, new object[] { initializer, new object() } ); ! } ! else { ! if( proxyType==null ) { CastleCustomProxyGenerator _classGenerator = new CastleCustomProxyGenerator( _scope, _context ); proxyType = _classGenerator.GenerateCode( concreteProxy ); ! cachedProxyTypes[ concreteProxy ] = proxyType; } ! ! generatedProxy = Activator.CreateInstance( proxyType, new object[] { initializer } ); ! } } ! return (INHibernateProxy)generatedProxy; } ! catch(Exception e) { ! log.Error("Castle Dynamic Class Generator failed", e); ! throw new HibernateException( "Castle Dynamic Class Generator failed", e); } } --- 88,115 ---- // hack with new object() because an interface proxy is expecting an actual target instance - we // don't have that yet and don't want to create it until it is actually needed. ! generatedProxy = Activator.CreateInstance( proxyType, new object[ ] {initializer, new object()} ); ! } ! else { ! if( proxyType == null ) { CastleCustomProxyGenerator _classGenerator = new CastleCustomProxyGenerator( _scope, _context ); proxyType = _classGenerator.GenerateCode( concreteProxy ); ! cachedProxyTypes[ concreteProxy ] = proxyType; } ! ! generatedProxy = Activator.CreateInstance( proxyType, new object[ ] {initializer} ); ! } } ! return ( INHibernateProxy ) generatedProxy; } ! catch( Exception e ) { ! log.Error( "Castle Dynamic Class Generator failed", e ); ! throw new HibernateException( "Castle Dynamic Class Generator failed", e ); } } *************** *** 122,126 **** /// <param name="proxy">The Proxy object</param> /// <returns>The <see cref="LazyInitializer"/> that contains the details of the Proxied object.</returns> ! public LazyInitializer GetLazyInitializer(INHibernateProxy proxy) { // have to hard code in "__interceptor" - very dependant on them not changing their --- 120,124 ---- /// <param name="proxy">The Proxy object</param> /// <returns>The <see cref="LazyInitializer"/> that contains the details of the Proxied object.</returns> ! public LazyInitializer GetLazyInitializer( INHibernateProxy proxy ) { // have to hard code in "__interceptor" - very dependant on them not changing their *************** *** 128,132 **** // field object fieldValue = proxy.GetType().GetField( "__interceptor" ).GetValue( proxy ); ! return (LazyInitializer)fieldValue; } --- 126,130 ---- // field object fieldValue = proxy.GetType().GetField( "__interceptor" ).GetValue( proxy ); ! return ( LazyInitializer ) fieldValue; } *************** *** 137,149 **** /// <param name="obj">The object to get the type of.</param> /// <returns>The Underlying Type for the object regardless of if it is a Proxy.</returns> ! public System.Type GetClass(object obj) { ! if (obj is INHibernateProxy) { ! INHibernateProxy proxy = (INHibernateProxy) obj; LazyInitializer li = GetLazyInitializer( proxy ); return li.PersistentClass; } ! else { return obj.GetType(); --- 135,147 ---- /// <param name="obj">The object to get the type of.</param> /// <returns>The Underlying Type for the object regardless of if it is a Proxy.</returns> ! public System.Type GetClass( object obj ) { ! if( obj is INHibernateProxy ) { ! INHibernateProxy proxy = ( INHibernateProxy ) obj; LazyInitializer li = GetLazyInitializer( proxy ); return li.PersistentClass; } ! else { return obj.GetType(); *************** *** 153,155 **** #endregion } ! } --- 151,153 ---- #endregion } ! } \ No newline at end of file Index: CastleCustomProxyGenerator.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Proxy/CastleCustomProxyGenerator.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CastleCustomProxyGenerator.cs 16 Dec 2004 21:51:48 -0000 1.2 --- CastleCustomProxyGenerator.cs 31 Dec 2004 22:08:10 -0000 1.3 *************** *** 1,4 **** using System; - using Castle.DynamicProxy; using Castle.DynamicProxy.Builder.CodeBuilder; --- 1,3 ---- *************** *** 12,25 **** /// interface to it. /// </summary> ! [CLSCompliant(false)] public class CastleCustomProxyGenerator : ClassProxyGenerator { ! public CastleCustomProxyGenerator(ModuleScope scope) ! : base(scope) { } ! public CastleCustomProxyGenerator(ModuleScope scope, GeneratorContext context) ! : base(scope, context) { } --- 11,33 ---- /// interface to it. /// </summary> ! [CLSCompliant( false )] public class CastleCustomProxyGenerator : ClassProxyGenerator { ! /// <summary> ! /// ! /// </summary> ! /// <param name="scope"></param> ! public CastleCustomProxyGenerator( ModuleScope scope ) ! : base( scope ) { } ! /// <summary> ! /// ! /// </summary> ! /// <param name="scope"></param> ! /// <param name="context"></param> ! public CastleCustomProxyGenerator( ModuleScope scope, GeneratorContext context ) ! : base( scope, context ) { } *************** *** 31,35 **** /// <param name="interfaces">The extra <see cref="System.Type"/> interfaces for the Proxy to implement.</param> /// <returns>An <see cref="EasyType"/> with the required interfaces added.</returns> ! protected override EasyType CreateTypeBuilder(System.Type baseType, System.Type[] interfaces) { bool isImplemented = false; --- 39,43 ---- /// <param name="interfaces">The extra <see cref="System.Type"/> interfaces for the Proxy to implement.</param> /// <returns>An <see cref="EasyType"/> with the required interfaces added.</returns> ! protected override EasyType CreateTypeBuilder( System.Type baseType, System.Type[ ] interfaces ) { bool isImplemented = false; *************** *** 37,43 **** // check to see if this implements INHibernateProxy - if not then make it // implement the interface ! for( int i=0; i<interfaces.Length; i++) { ! if( interfaces[i].Equals( typeof(INHibernateProxy) ) ) { isImplemented = true; --- 45,51 ---- // check to see if this implements INHibernateProxy - if not then make it // implement the interface ! for( int i = 0; i < interfaces.Length; i++ ) { ! if( interfaces[ i ].Equals( typeof( INHibernateProxy ) ) ) { isImplemented = true; *************** *** 45,60 **** } ! if( isImplemented==false ) { int length = interfaces.Length; ! System.Type[] newInterfaces = new System.Type[ length + 1 ]; Array.Copy( interfaces, 0, newInterfaces, 0, length ); ! newInterfaces[ length ] = typeof(INHibernateProxy); interfaces = newInterfaces; } ! return base.CreateTypeBuilder(baseType, interfaces); } } ! } --- 53,68 ---- } ! if( isImplemented == false ) { int length = interfaces.Length; ! System.Type[ ] newInterfaces = new System.Type[length + 1]; Array.Copy( interfaces, 0, newInterfaces, 0, length ); ! newInterfaces[ length ] = typeof( INHibernateProxy ); interfaces = newInterfaces; } ! return base.CreateTypeBuilder( baseType, interfaces ); } } ! } \ No newline at end of file |