TransactionHelper reads private field names instead of public property names.
Opened this issue · 0 comments
Kuffs2205 commented
internal static Dictionary<String, Object> ConvertInstanceToMap<E>( E instance )
{
if( instance == null )
throw new ArgumentException( ExceptionMessage.NULL_INSTANCE );
Dictionary<String, Object> entity = new Dictionary<String, Object>();
Type fieldsType = typeof( E );
FieldInfo[] fields = fieldsType.GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance );
foreach( FieldInfo field in fields )
entity[ field.Name ] = field.GetValue( instance );
return entity;
}
internal static String GetObjectIdFromInstance<E>( E instance )
{
if( instance == null )
throw new ArgumentException( ExceptionMessage.NULL_INSTANCE );
Type fieldsType = typeof( E );
FieldInfo[] fields = fieldsType.GetFields( BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance );
foreach( FieldInfo field in fields )
if( field.Name == "objectId" || field.Name == "ObjectId" )
return (String) field.GetValue( instance );
throw new ArgumentException( ExceptionMessage.NULL_OBJECT_ID_IN_INSTANCE );
}
These two methods read the field names from a Business Object rather than the property names. Because of that, transactions fail as it is looking for "objectId" etc when the field name is "_objectId" but the property name is "objectId"
Private fields tend to be internal to the class. Is it really the intention that it work this way?
I fixed it in my own project by forking the source and replacing FieldInfo with PropertyInfo for these two methods but I would rather stick with official releases.