1010
1111namespace NHibernate
1212{
13- using System . Collections . Generic ;
14- using System . Reflection ;
15-
1613 /// <summary>
1714 /// Provides access to the full range of NHibernate built-in types.
1815 /// IType instances may be used to bind values to query parameters.
1916 /// Also a factory for new Blobs and Clobs.
2017 /// </summary>
2118 public static partial class NHibernateUtil
2219 {
23- static private readonly Dictionary < System . Type , IType > clrTypeToNHibernateType = new Dictionary < System . Type , IType > ( ) ;
24-
25- static NHibernateUtil ( )
26- {
27- FieldInfo [ ] fields = typeof ( NHibernateUtil ) . GetFields ( ) ;
28- foreach ( FieldInfo info in fields )
29- {
30- if ( typeof ( IType ) . IsAssignableFrom ( info . FieldType ) == false )
31- continue ;
32- IType type = ( IType ) info . GetValue ( null ) ;
33- clrTypeToNHibernateType [ type . ReturnedClass ] = type ;
34- }
35-
36- // There are multiple possibilites for boolean and strings.
37- // Override so that we use the most natural mapping.
38- clrTypeToNHibernateType [ Boolean . ReturnedClass ] = Boolean ;
39- clrTypeToNHibernateType [ String . ReturnedClass ] = String ;
40- }
41-
4220 /// <summary>
4321 /// Guesses the IType of this object
4422 /// </summary>
@@ -59,8 +37,8 @@ public static IType GuessType(System.Type type)
5937 {
6038 type = type . UnwrapIfNullable ( ) ;
6139
62- IType value ;
63- if ( clrTypeToNHibernateType . TryGetValue ( type , out value ) )
40+ var value = TypeFactory . GetDefaultTypeFor ( type ) ;
41+ if ( value != null )
6442 return value ;
6543
6644 if ( type . IsEnum )
@@ -71,7 +49,7 @@ public static IType GuessType(System.Type type)
7149 {
7250 return Custom ( type ) ;
7351 }
74-
52+
7553 return Entity ( type ) ;
7654 }
7755
@@ -381,13 +359,13 @@ public static void Initialize(object proxy)
381359 {
382360 return ;
383361 }
384- else if ( proxy . IsProxy ( ) )
362+ if ( proxy . IsProxy ( ) )
385363 {
386364 ( ( INHibernateProxy ) proxy ) . HibernateLazyInitializer . Initialize ( ) ;
387365 }
388- else if ( proxy is IPersistentCollection )
366+ else if ( proxy is IPersistentCollection coll )
389367 {
390- ( ( IPersistentCollection ) proxy ) . ForceInitialization ( ) ;
368+ coll . ForceInitialization ( ) ;
391369 }
392370 }
393371
@@ -513,7 +491,7 @@ public static void Close(IEnumerator enumerator)
513491 EnumerableImpl hibernateEnumerator = enumerator as EnumerableImpl ;
514492 if ( hibernateEnumerator == null )
515493 {
516- throw new ArgumentException ( "Not a NHibernate enumerator" , " enumerator" ) ;
494+ throw new ArgumentException ( "Not a NHibernate enumerator" , nameof ( enumerator ) ) ;
517495 }
518496 hibernateEnumerator . Dispose ( ) ;
519497 }
@@ -527,7 +505,7 @@ public static void Close(IEnumerable enumerable)
527505 EnumerableImpl hibernateEnumerable = enumerable as EnumerableImpl ;
528506 if ( hibernateEnumerable == null )
529507 {
530- throw new ArgumentException ( "Not a NHibernate enumerable" , " enumerable" ) ;
508+ throw new ArgumentException ( "Not a NHibernate enumerable" , nameof ( enumerable ) ) ;
531509 }
532510 hibernateEnumerable . Dispose ( ) ;
533511 }
0 commit comments