10
10
11
11
namespace NHibernate
12
12
{
13
- using System . Collections . Generic ;
14
- using System . Reflection ;
15
-
16
13
/// <summary>
17
14
/// Provides access to the full range of NHibernate built-in types.
18
15
/// IType instances may be used to bind values to query parameters.
19
16
/// Also a factory for new Blobs and Clobs.
20
17
/// </summary>
21
18
public static partial class NHibernateUtil
22
19
{
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
-
42
20
/// <summary>
43
21
/// Guesses the IType of this object
44
22
/// </summary>
@@ -59,8 +37,8 @@ public static IType GuessType(System.Type type)
59
37
{
60
38
type = type . UnwrapIfNullable ( ) ;
61
39
62
- IType value ;
63
- if ( clrTypeToNHibernateType . TryGetValue ( type , out value ) )
40
+ var value = TypeFactory . GetDefaultTypeFor ( type ) ;
41
+ if ( value != null )
64
42
return value ;
65
43
66
44
if ( type . IsEnum )
@@ -71,7 +49,7 @@ public static IType GuessType(System.Type type)
71
49
{
72
50
return Custom ( type ) ;
73
51
}
74
-
52
+
75
53
return Entity ( type ) ;
76
54
}
77
55
@@ -381,13 +359,13 @@ public static void Initialize(object proxy)
381
359
{
382
360
return ;
383
361
}
384
- else if ( proxy . IsProxy ( ) )
362
+ if ( proxy . IsProxy ( ) )
385
363
{
386
364
( ( INHibernateProxy ) proxy ) . HibernateLazyInitializer . Initialize ( ) ;
387
365
}
388
- else if ( proxy is IPersistentCollection )
366
+ else if ( proxy is IPersistentCollection coll )
389
367
{
390
- ( ( IPersistentCollection ) proxy ) . ForceInitialization ( ) ;
368
+ coll . ForceInitialization ( ) ;
391
369
}
392
370
}
393
371
@@ -513,7 +491,7 @@ public static void Close(IEnumerator enumerator)
513
491
EnumerableImpl hibernateEnumerator = enumerator as EnumerableImpl ;
514
492
if ( hibernateEnumerator == null )
515
493
{
516
- throw new ArgumentException ( "Not a NHibernate enumerator" , " enumerator" ) ;
494
+ throw new ArgumentException ( "Not a NHibernate enumerator" , nameof ( enumerator ) ) ;
517
495
}
518
496
hibernateEnumerator . Dispose ( ) ;
519
497
}
@@ -527,7 +505,7 @@ public static void Close(IEnumerable enumerable)
527
505
EnumerableImpl hibernateEnumerable = enumerable as EnumerableImpl ;
528
506
if ( hibernateEnumerable == null )
529
507
{
530
- throw new ArgumentException ( "Not a NHibernate enumerable" , " enumerable" ) ;
508
+ throw new ArgumentException ( "Not a NHibernate enumerable" , nameof ( enumerable ) ) ;
531
509
}
532
510
hibernateEnumerable . Dispose ( ) ;
533
511
}
0 commit comments