From: Paul H. <pha...@us...> - 2005-03-14 14:38:18
|
Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv726/nhibernate/src/NHibernate/Util Modified Files: ReflectHelper.cs Log Message: Modified type reflector to take access strategy - speeds up mapping loading by avoiding unnecessary exceptions Index: ReflectHelper.cs =================================================================== RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Util/ReflectHelper.cs,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** ReflectHelper.cs 1 Mar 2005 16:24:50 -0000 1.23 --- ReflectHelper.cs 14 Mar 2005 14:37:59 -0000 1.24 *************** *** 50,86 **** } - //TODO: most calls to this will be replaced by the Mapping.Property.GetGetter() but - // there will still be a call from hql into this. /// <summary> /// Finds the <see cref="IGetter"/> for the property in the <see cref="System.Type"/>. /// </summary> ! /// <param name="theClass">The <see cref="System.Type"/> to find the Property/Field in.</param> ! /// <param name="propertyName">The name of the Property/Field to find.</param> ! /// <returns>The <see cref="IGetter"/> for the property.</returns> /// <remarks> ! /// <para> ! /// This does not use the <c>access=""</c> attribute specified in the mapping. It ! /// first checks to see if there is a Property in your class with the same name. If ! /// no Property is found then it moves through each <see cref="IPropertyAccessor"/> strategy ! /// and tries to find an <see cref="IGetter"/> through them. ! /// </para> /// </remarks> ! /// <exception cref="PropertyNotFoundException"> ! /// No Property or Field with the <c>propertyName</c> could be found. ! /// </exception> ! public static IGetter GetGetter( System.Type theClass, string propertyName ) { IPropertyAccessor accessor = null; - // first try the basicPropertyAccessor since that will be the most likely - // strategy used. try { ! accessor = ( IPropertyAccessor ) PropertyAccessorFactory.PropertyAccessors[ "property" ]; return accessor.GetGetter( theClass, propertyName ); } catch( PropertyNotFoundException ) { ! // the basic "property" strategy did not work so try the rest of them foreach( DictionaryEntry de in PropertyAccessorFactory.PropertyAccessors ) { --- 50,76 ---- } /// <summary> /// Finds the <see cref="IGetter"/> for the property in the <see cref="System.Type"/>. /// </summary> ! /// <param name="theClass"></param> ! /// <param name="propertyName"></param> ! /// <param name="propertyAccessorName"></param> ! /// <returns></returns> /// <remarks> ! /// This one takes a propertyAccessor name as we might know the correct strategy by now so we avoid Exceptions which are costly /// </remarks> ! public static IGetter GetGetter( System.Type theClass, string propertyName, string propertyAccessorName ) { IPropertyAccessor accessor = null; try { ! // first try the named strategy since that will be the most likely strategy used. ! accessor = ( IPropertyAccessor ) PropertyAccessorFactory.PropertyAccessors[ propertyAccessorName ]; return accessor.GetGetter( theClass, propertyName ); } catch( PropertyNotFoundException ) { ! // the basic named strategy did not work so try the rest of them foreach( DictionaryEntry de in PropertyAccessorFactory.PropertyAccessors ) { *************** *** 95,105 **** // the rest of the accessor strategies. } - } - throw; } } //TODO: add a method in here ReflectedPropertyClass and replace most calls to GetGetter // with calls to it --- 85,118 ---- // the rest of the accessor strategies. } } throw; } } + //TODO: most calls to this will be replaced by the Mapping.Property.GetGetter() but + // there will still be a call from hql into this. + /// <summary> + /// Finds the <see cref="IGetter"/> for the property in the <see cref="System.Type"/>. + /// </summary> + /// <param name="theClass">The <see cref="System.Type"/> to find the Property/Field in.</param> + /// <param name="propertyName">The name of the Property/Field to find.</param> + /// <returns>The <see cref="IGetter"/> for the property.</returns> + /// <remarks> + /// <para> + /// This does not use the <c>access=""</c> attribute specified in the mapping. It + /// first checks to see if there is a Property in your class with the same name. If + /// no Property is found then it moves through each <see cref="IPropertyAccessor"/> strategy + /// and tries to find an <see cref="IGetter"/> through them. + /// </para> + /// </remarks> + /// <exception cref="PropertyNotFoundException"> + /// No Property or Field with the <c>propertyName</c> could be found. + /// </exception> + public static IGetter GetGetter( System.Type theClass, string propertyName ) + { + // first try the basicPropertyAccessor since that will be the most likely strategy used. + return GetGetter( theClass, propertyName, "property" ); + } + //TODO: add a method in here ReflectedPropertyClass and replace most calls to GetGetter // with calls to it *************** *** 111,120 **** /// <param name="theClass">The <see cref="System.Type"/> to find the Property in.</param> /// <param name="name">The name of the property/field to find in the class.</param> /// <returns> /// The NHibernate <see cref="IType"/> for the named property. /// </returns> ! public static IType ReflectedPropertyType( System.Type theClass, string name ) { ! return TypeFactory.HueristicType( GetGetter( theClass, name ).ReturnType.AssemblyQualifiedName ); } --- 124,134 ---- /// <param name="theClass">The <see cref="System.Type"/> to find the Property in.</param> /// <param name="name">The name of the property/field to find in the class.</param> + /// <param name="propertyAccess"></param> /// <returns> /// The NHibernate <see cref="IType"/> for the named property. /// </returns> ! public static IType ReflectedPropertyType( System.Type theClass, string name, string propertyAccess ) { ! return TypeFactory.HueristicType( GetGetter( theClass, name, propertyAccess ).ReturnType.AssemblyQualifiedName ); } |