@@ -356,16 +356,28 @@ protected virtual void RegisterIdBagMapping<TElement>(Action<IIdBagPropertiesMap
356
356
public void Set < TElement > ( string notVisiblePropertyOrFieldName , Action < ISetPropertiesMapper < TEntity , TElement > > collectionMapping , Action < ICollectionElementRelation < TElement > > mapping )
357
357
{
358
358
MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
359
- var collectionElementType = member . GetPropertyOrFieldType ( ) . DetermineCollectionElementType ( ) ;
360
- if ( ! typeof ( TElement ) . Equals ( collectionElementType ) )
361
- {
362
- throw new MappingException ( string . Format ( "Wrong collection element type. For the property/field '{0}' of {1} was expected a collection of {2} but was {3}" ,
363
- notVisiblePropertyOrFieldName , typeof ( TEntity ) . FullName , typeof ( TElement ) . Name , collectionElementType . Name ) ) ;
364
- }
359
+ AssertCollectionElementType < TElement > ( notVisiblePropertyOrFieldName , member ) ;
360
+
365
361
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
366
362
RegisterSetMapping < TElement > ( collectionMapping , mapping , member , memberOf ) ;
367
363
}
368
364
365
+
366
+ private static void AssertCollectionElementType < TElement > ( string propertyOrFieldName , MemberInfo memberInfo )
367
+ {
368
+ System . Type collectionElementType = memberInfo . GetPropertyOrFieldType ( ) . DetermineCollectionElementType ( ) ;
369
+
370
+ if ( typeof ( TElement ) != collectionElementType )
371
+ {
372
+ var message = string . Format (
373
+ "Wrong collection element type. For the property/field '{0}' of {1} was expected a generic collection of {2} but was {3}" ,
374
+ propertyOrFieldName , typeof ( TEntity ) . FullName , typeof ( TElement ) . Name ,
375
+ collectionElementType != null ? collectionElementType . Name : "unknown" ) ;
376
+ throw new MappingException ( message ) ;
377
+ }
378
+ }
379
+
380
+
369
381
public void Set < TElement > ( string notVisiblePropertyOrFieldName , Action < ISetPropertiesMapper < TEntity , TElement > > collectionMapping )
370
382
{
371
383
Set ( notVisiblePropertyOrFieldName , collectionMapping , x => { } ) ;
@@ -374,12 +386,8 @@ public void Set<TElement>(string notVisiblePropertyOrFieldName, Action<ISetPrope
374
386
public void Bag < TElement > ( string notVisiblePropertyOrFieldName , Action < IBagPropertiesMapper < TEntity , TElement > > collectionMapping , Action < ICollectionElementRelation < TElement > > mapping )
375
387
{
376
388
MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
377
- var collectionElementType = member . GetPropertyOrFieldType ( ) . DetermineCollectionElementType ( ) ;
378
- if ( ! typeof ( TElement ) . Equals ( collectionElementType ) )
379
- {
380
- throw new MappingException ( string . Format ( "Wrong collection element type. For the property/field '{0}' of {1} was expected a collection of {2} but was {3}" ,
381
- notVisiblePropertyOrFieldName , typeof ( TEntity ) . FullName , typeof ( TElement ) . Name , collectionElementType . Name ) ) ;
382
- }
389
+ AssertCollectionElementType < TElement > ( notVisiblePropertyOrFieldName , member ) ;
390
+
383
391
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
384
392
RegisterBagMapping < TElement > ( collectionMapping , mapping , member , memberOf ) ;
385
393
}
@@ -392,12 +400,8 @@ public void Bag<TElement>(string notVisiblePropertyOrFieldName, Action<IBagPrope
392
400
public void List < TElement > ( string notVisiblePropertyOrFieldName , Action < IListPropertiesMapper < TEntity , TElement > > collectionMapping , Action < ICollectionElementRelation < TElement > > mapping )
393
401
{
394
402
MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
395
- var collectionElementType = member . GetPropertyOrFieldType ( ) . DetermineCollectionElementType ( ) ;
396
- if ( ! typeof ( TElement ) . Equals ( collectionElementType ) )
397
- {
398
- throw new MappingException ( string . Format ( "Wrong collection element type. For the property/field '{0}' of {1} was expected a collection of {2} but was {3}" ,
399
- notVisiblePropertyOrFieldName , typeof ( TEntity ) . FullName , typeof ( TElement ) . Name , collectionElementType . Name ) ) ;
400
- }
403
+ AssertCollectionElementType < TElement > ( notVisiblePropertyOrFieldName , member ) ;
404
+
401
405
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
402
406
RegisterListMapping < TElement > ( collectionMapping , mapping , member , memberOf ) ;
403
407
}
@@ -435,12 +439,8 @@ public void Map<TKey, TElement>(string notVisiblePropertyOrFieldName, Action<IMa
435
439
public void IdBag < TElement > ( string notVisiblePropertyOrFieldName , Action < IIdBagPropertiesMapper < TEntity , TElement > > collectionMapping , Action < ICollectionElementRelation < TElement > > mapping )
436
440
{
437
441
MemberInfo member = GetPropertyOrFieldMatchingNameOrThrow ( notVisiblePropertyOrFieldName ) ;
438
- var collectionElementType = member . GetPropertyOrFieldType ( ) . DetermineCollectionElementType ( ) ;
439
- if ( ! typeof ( TElement ) . Equals ( collectionElementType ) )
440
- {
441
- throw new MappingException ( string . Format ( "Wrong collection element type. For the property/field '{0}' of {1} was expected a collection of {2} but was {3}" ,
442
- notVisiblePropertyOrFieldName , typeof ( TEntity ) . FullName , typeof ( TElement ) . Name , collectionElementType . Name ) ) ;
443
- }
442
+ AssertCollectionElementType < TElement > ( notVisiblePropertyOrFieldName , member ) ;
443
+
444
444
MemberInfo memberOf = member . GetMemberFromReflectedType ( typeof ( TEntity ) ) ;
445
445
RegisterIdBagMapping < TElement > ( collectionMapping , mapping , member , memberOf ) ;
446
446
}
0 commit comments