Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
NHibernate 1.0.2 (ASP.NET 2.0)
I'm using NHibernate.Generics and there seems to be a minor flaw in the reflection optimizer. The relevant code from GetSetHelperFactory.GenerateCode() is excerpted below. The problem is that if setters[i] is a GenericAccessor, setters[i].Property can be null, and the line
Code:
System.Type type = setters[ i ].Property.PropertyType;
throws a NullReferenceException, effectively disabling the reflection optimizer for the class. I fixed this by moving the offending line into the scope of the if (setter is BasicSetter ... ). This doesn't change the semantics of the code in any way, and the generated code appears to function correctly.
Code:
private string GenerateCode()
{
StringBuilder sb = new StringBuilder();
sb.Append( header );
sb.AppendFormat( classDef, mappedClass.FullName.Replace( '.', '_' ).Replace( "+", "__" ) );
sb.AppendFormat( startSetMethod, mappedClass.FullName.Replace( '+', '.' ) );
for( int i = 0; i < setters.Length; i++ )
{
ISetter setter = setters[ i ];
System.Type type = setters[ i ].Property.PropertyType;
if( setter is BasicSetter && IsPublic( setter.PropertyName ) )
{
if( type.IsValueType )
{
sb.AppendFormat(
" t.{0} = values[{2}] == null ? new {1}() : ({1})values[{2}];\n",
setter.PropertyName,
type.FullName.Replace( '+', '.' ),
i );
}
else
{
sb.AppendFormat( " t.{0} = ({1})values[{2}];\n",
setter.PropertyName,
type.FullName.Replace( '+', '.' ),
i );
}
}
else
{
sb.AppendFormat( " setters[{0}].Set(obj, values[{0}]);\n", i );
}
}