Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Util
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20833/NHibernate/Util
Modified Files:
ReflectHelper.cs
Log Message:
NH-134
Index: ReflectHelper.cs
===================================================================
RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Util/ReflectHelper.cs,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** ReflectHelper.cs 27 Sep 2004 01:48:16 -0000 1.16
--- ReflectHelper.cs 23 Oct 2004 15:01:23 -0000 1.17
***************
*** 1,4 ****
--- 1,7 ----
using System;
+ using System.Collections;
using System.Reflection;
+
+ using NHibernate.Property;
using NHibernate.Type;
***************
*** 10,16 ****
public sealed class ReflectHelper
{
- //TODO: this dependency is kind of bad - H2.0.3 comment
- private static readonly Property.BasicPropertyAccessor basicPropertyAccessor = new Property.BasicPropertyAccessor();
-
private static System.Type[] NoClasses = new System.Type[0];
private static System.Type[] Object = new System.Type[] { typeof(object) };
--- 13,16 ----
***************
*** 53,65 ****
//TODO: most calls to this will be replaced by the Mapping.Property.GetGetter() but
// there will still be a call from hql into this.
! public static Property.IGetter GetGetter(System.Type theClass, string propertyName)
{
try
{
! return basicPropertyAccessor.GetGetter(theClass, propertyName);
}
! catch (PropertyNotFoundException pnfe)
{
! //TODO: figure out how we are going to know the field accessor to use here...
throw pnfe;
}
--- 53,102 ----
//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 pnfe )
{
! // the basic "property" strategy did not work so try the rest of them
! foreach( DictionaryEntry de in Property.PropertyAccessorFactory.PropertyAccessors )
! {
! try
! {
! accessor = (IPropertyAccessor)de.Value;
! return accessor.GetGetter( theClass, propertyName );
! }
! catch( PropertyNotFoundException )
! {
! // ignore this exception because we want to try and move through
! // the rest of the accessor strategies.
! }
!
! }
!
throw pnfe;
}
|