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.
@@ -21,26 +18,6 @@ namespace NHibernate
21
18
/// </summary>
22
19
public static partial class NHibernateUtil
23
20
{
24
- static private readonly Dictionary < System . Type , IType > clrTypeToNHibernateType = new Dictionary < System . Type , IType > ( ) ;
25
-
26
- static NHibernateUtil ( )
27
- {
28
- FieldInfo [ ] fields = typeof ( NHibernateUtil ) . GetFields ( ) ;
29
- foreach ( FieldInfo info in fields )
30
- {
31
- if ( typeof ( IType ) . IsAssignableFrom ( info . FieldType ) == false )
32
- continue ;
33
- IType type = ( IType ) info . GetValue ( null ) ;
34
- clrTypeToNHibernateType [ type . ReturnedClass ] = type ;
35
- }
36
-
37
- // There are multiple possibilites for boolean, strings and datetime.
38
- // Override so that we use the most natural mapping.
39
- clrTypeToNHibernateType [ Boolean . ReturnedClass ] = Boolean ;
40
- clrTypeToNHibernateType [ String . ReturnedClass ] = String ;
41
- clrTypeToNHibernateType [ DateTime . ReturnedClass ] = DateTime ;
42
- }
43
-
44
21
/// <summary>
45
22
/// Guesses the IType of this object
46
23
/// </summary>
@@ -61,8 +38,8 @@ public static IType GuessType(System.Type type)
61
38
{
62
39
type = type . UnwrapIfNullable ( ) ;
63
40
64
- IType value ;
65
- if ( clrTypeToNHibernateType . TryGetValue ( type , out value ) )
41
+ var value = TypeFactory . GetDefaultTypeFor ( type ) ;
42
+ if ( value != null )
66
43
return value ;
67
44
68
45
if ( type . IsEnum )
@@ -73,7 +50,7 @@ public static IType GuessType(System.Type type)
73
50
{
74
51
return Custom ( type ) ;
75
52
}
76
-
53
+
77
54
return Entity ( type ) ;
78
55
}
79
56
@@ -401,13 +378,13 @@ public static void Initialize(object proxy)
401
378
{
402
379
return ;
403
380
}
404
- else if ( proxy . IsProxy ( ) )
381
+ if ( proxy . IsProxy ( ) )
405
382
{
406
383
( ( INHibernateProxy ) proxy ) . HibernateLazyInitializer . Initialize ( ) ;
407
384
}
408
- else if ( proxy is IPersistentCollection )
385
+ else if ( proxy is IPersistentCollection coll )
409
386
{
410
- ( ( IPersistentCollection ) proxy ) . ForceInitialization ( ) ;
387
+ coll . ForceInitialization ( ) ;
411
388
}
412
389
}
413
390
@@ -533,7 +510,7 @@ public static void Close(IEnumerator enumerator)
533
510
EnumerableImpl hibernateEnumerator = enumerator as EnumerableImpl ;
534
511
if ( hibernateEnumerator == null )
535
512
{
536
- throw new ArgumentException ( "Not a NHibernate enumerator" , " enumerator" ) ;
513
+ throw new ArgumentException ( "Not a NHibernate enumerator" , nameof ( enumerator ) ) ;
537
514
}
538
515
hibernateEnumerator . Dispose ( ) ;
539
516
}
@@ -547,7 +524,7 @@ public static void Close(IEnumerable enumerable)
547
524
EnumerableImpl hibernateEnumerable = enumerable as EnumerableImpl ;
548
525
if ( hibernateEnumerable == null )
549
526
{
550
- throw new ArgumentException ( "Not a NHibernate enumerable" , " enumerable" ) ;
527
+ throw new ArgumentException ( "Not a NHibernate enumerable" , nameof ( enumerable ) ) ;
551
528
}
552
529
hibernateEnumerable . Dispose ( ) ;
553
530
}
0 commit comments