1
1
using System ;
2
2
using System . Linq . Expressions ;
3
3
using System . Reflection ;
4
+ using NHibernate . Mapping . ByCode . Impl ;
5
+ using NHibernate . Mapping . ByCode . Impl . CustomizersImpl ;
4
6
using NHibernate . Persister . Collection ;
5
7
using NHibernate . UserTypes ;
8
+ using NHibernate . Util ;
6
9
7
10
namespace NHibernate . Mapping . ByCode
8
11
{
@@ -54,4 +57,46 @@ public interface ICollectionPropertiesMapper<TEntity, TElement> : IEntityPropert
54
57
void Fetch ( CollectionFetchMode fetchMode ) ;
55
58
void Persister < TPersister > ( ) where TPersister : ICollectionPersister ;
56
59
}
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
+ }
57
102
}
0 commit comments