Update of /cvsroot/nhibernate/nhibernate/src/NHibernate/Property
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2690/NHibernate/Property
Modified Files:
BasicSetter.cs FieldSetter.cs
Log Message:
Added better error messages to the setters to help with the problem
of ISet and IDictionary.
Index: FieldSetter.cs
===================================================================
RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Property/FieldSetter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** FieldSetter.cs 13 Jan 2005 20:55:16 -0000 1.3
--- FieldSetter.cs 17 Jan 2005 05:54:40 -0000 1.4
***************
*** 1,4 ****
--- 1,5 ----
using System;
using System.Reflection;
+ using System.Text;
namespace NHibernate.Property
***************
*** 42,45 ****
--- 43,62 ----
field.SetValue( target, value );
}
+ catch( ArgumentException ae )
+ {
+ // if I'm reading the msdn docs correctly this is the only reason the ArgumentException
+ // would be thrown, but it doesn't hurt to make sure.
+ if( field.FieldType.IsAssignableFrom( value.GetType() )==false )
+ {
+ // add some details to the error message - there have been a few forum posts an they are
+ // all related to an ISet and IDictionary mixups.
+ string msg = String.Format( "The type {0} can not be assigned to a field of type {1}", value.GetType().ToString(), field.FieldType.ToString() );
+ throw new PropertyAccessException( ae, msg, true, clazz, name );
+ }
+ else
+ {
+ throw new PropertyAccessException( ae, "ArgumentException while setting the field value by reflection", true, clazz, name );
+ }
+ }
catch( Exception e )
{
Index: BasicSetter.cs
===================================================================
RCS file: /cvsroot/nhibernate/nhibernate/src/NHibernate/Property/BasicSetter.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** BasicSetter.cs 14 Jan 2005 00:28:26 -0000 1.4
--- BasicSetter.cs 17 Jan 2005 05:54:40 -0000 1.5
***************
*** 42,48 ****
property.SetValue( target, value, new object[0] );
}
catch( Exception e )
{
! throw new PropertyAccessException( e, "Exception occurred", true, clazz, propertyName );
}
}
--- 42,64 ----
property.SetValue( target, value, new object[0] );
}
+ catch( ArgumentException ae )
+ {
+ // if I'm reading the msdn docs correctly this is the only reason the ArgumentException
+ // would be thrown, but it doesn't hurt to make sure.
+ if( property.PropertyType.IsAssignableFrom( value.GetType() )==false )
+ {
+ // add some details to the error message - there have been a few forum posts an they are
+ // all related to an ISet and IDictionary mixups.
+ string msg = String.Format( "The type {0} can not be assigned to a property of type {1}", value.GetType().ToString(), property.PropertyType.ToString() );
+ throw new PropertyAccessException( ae, msg, true, clazz, propertyName );
+ }
+ else
+ {
+ throw new PropertyAccessException( ae, "ArgumentException while setting the property value by reflection", true, clazz, propertyName );
+ }
+ }
catch( Exception e )
{
! throw new PropertyAccessException( e, "could not set a property value by reflection", true, clazz, propertyName );
}
}
|