11using System ;
22using System . Linq . Expressions ;
33using System . Reflection ;
4+ using NHibernate . Mapping . ByCode . Impl ;
5+ using NHibernate . Mapping . ByCode . Impl . CustomizersImpl ;
46using NHibernate . Persister . Collection ;
57using NHibernate . UserTypes ;
8+ using NHibernate . Util ;
69
710namespace NHibernate . Mapping . ByCode
811{
@@ -54,4 +57,46 @@ public interface ICollectionPropertiesMapper<TEntity, TElement> : IEntityPropert
5457 void Fetch ( CollectionFetchMode fetchMode ) ;
5558 void Persister < TPersister > ( ) where TPersister : ICollectionPersister ;
5659 }
60+
61+ public static class CollectionPropertiesMapperExtensions
62+ {
63+ //6.0 TODO: Merge into ICollectionPropertiesMapper<TEntity, TElement>
64+ public static void Type < TEntity , TElement > (
65+ this ICollectionPropertiesMapper < TEntity , TElement > mapper ,
66+ string collectionType )
67+ {
68+ ReflectHelper
69+ . CastOrThrow < CollectionPropertiesCustomizer < TEntity , TElement > > ( mapper , "Type(string)" )
70+ . Type ( collectionType ) ;
71+ }
72+
73+ //6.0 TODO: Merge into ICollectionPropertiesMapper
74+ public static void Type (
75+ this ICollectionPropertiesMapper mapper ,
76+ string collectionType )
77+ {
78+ if ( mapper == null ) throw new ArgumentNullException ( nameof ( mapper ) ) ;
79+
80+ switch ( mapper )
81+ {
82+ case BagMapper bagMapper :
83+ bagMapper . Type ( collectionType ) ;
84+ break ;
85+ case IdBagMapper idBagMapper :
86+ idBagMapper . Type ( collectionType ) ;
87+ break ;
88+ case ListMapper listMapper :
89+ listMapper . Type ( collectionType ) ;
90+ break ;
91+ case MapMapper mapMapper :
92+ mapMapper . Type ( collectionType ) ;
93+ break ;
94+ case SetMapper setMapper :
95+ setMapper . Type ( collectionType ) ;
96+ break ;
97+ default :
98+ throw new NotSupportedException ( $ "{ mapper . GetType ( ) . FullName } does not support Type(string)") ;
99+ }
100+ }
101+ }
57102}
0 commit comments