@@ -14,29 +14,27 @@ internal static class ParameterHelper
14
14
/// </summary>
15
15
/// <param name="param">The object to guess the <see cref="IType"/> of.</param>
16
16
/// <param name="sessionFactory">The session factory to search for entity persister.</param>
17
- /// <param name="isCollection">The output parameter that represents whether the <paramref name="param"/> is a collection.</param>
17
+ /// <param name="isCollection">Whether <paramref name="param"/> is a collection.</param>
18
18
/// <returns>An <see cref="IType"/> for the object.</returns>
19
19
/// <exception cref="ArgumentNullException">
20
20
/// Thrown when the <c>param</c> is null because the <see cref="IType"/>
21
21
/// can't be guess from a null value.
22
22
/// </exception>
23
- public static IType TryGuessType ( object param , ISessionFactoryImplementor sessionFactory , out bool isCollection )
23
+ public static IType TryGuessType ( object param , ISessionFactoryImplementor sessionFactory , bool isCollection )
24
24
{
25
25
if ( param == null )
26
26
{
27
- throw new ArgumentNullException ( nameof ( param ) , "The IType can not be guessed for a null value." ) ;
27
+ return null ;
28
28
}
29
29
30
- if ( param is IEnumerable enumerable && ! ( param is string ) )
30
+ if ( param is IEnumerable enumerable && isCollection )
31
31
{
32
32
var firstValue = enumerable . Cast < object > ( ) . FirstOrDefault ( ) ;
33
- isCollection = true ;
34
33
return firstValue == null
35
34
? TryGuessType ( enumerable . GetCollectionElementType ( ) , sessionFactory )
36
- : TryGuessType ( firstValue , sessionFactory , out _ ) ;
35
+ : TryGuessType ( firstValue , sessionFactory , false ) ;
37
36
}
38
37
39
- isCollection = false ;
40
38
var clazz = NHibernateProxyHelper . GetClassWithoutInitializingProxy ( param ) ;
41
39
return TryGuessType ( clazz , sessionFactory ) ;
42
40
}
@@ -67,26 +65,24 @@ public static IType GuessType(object param, ISessionFactoryImplementor sessionFa
67
65
/// </summary>
68
66
/// <param name="clazz">The <see cref="System.Type"/> to guess the <see cref="IType"/> of.</param>
69
67
/// <param name="sessionFactory">The session factory to search for entity persister.</param>
70
- /// <param name="isCollection">The output parameter that represents whether the <paramref name="clazz"/> is a collection.</param>
68
+ /// <param name="isCollection">Whether <paramref name="clazz"/> is a collection.</param>
71
69
/// <returns>An <see cref="IType"/> for the <see cref="System.Type"/>.</returns>
72
70
/// <exception cref="ArgumentNullException">
73
71
/// Thrown when the <c>clazz</c> is null because the <see cref="IType"/>
74
72
/// can't be guess from a null type.
75
73
/// </exception>
76
- public static IType TryGuessType ( System . Type clazz , ISessionFactoryImplementor sessionFactory , out bool isCollection )
74
+ public static IType TryGuessType ( System . Type clazz , ISessionFactoryImplementor sessionFactory , bool isCollection )
77
75
{
78
76
if ( clazz == null )
79
77
{
80
- throw new ArgumentNullException ( nameof ( clazz ) , "The IType can not be guessed for a null value." ) ;
78
+ return null ;
81
79
}
82
80
83
- if ( clazz . IsCollectionType ( ) )
81
+ if ( isCollection )
84
82
{
85
- isCollection = true ;
86
- return TryGuessType ( ReflectHelper . GetCollectionElementType ( clazz ) , sessionFactory , out _ ) ;
83
+ return TryGuessType ( ReflectHelper . GetCollectionElementType ( clazz ) , sessionFactory , false ) ;
87
84
}
88
85
89
- isCollection = false ;
90
86
return TryGuessType ( clazz , sessionFactory ) ;
91
87
}
92
88
@@ -95,41 +91,18 @@ public static IType TryGuessType(System.Type clazz, ISessionFactoryImplementor s
95
91
/// </summary>
96
92
/// <param name="clazz">The <see cref="System.Type"/> to guess the <see cref="IType"/> of.</param>
97
93
/// <param name="sessionFactory">The session factory to search for entity persister.</param>
98
- /// <param name="isCollection">The output parameter that represents whether the <paramref name="clazz"/> is a collection.</param>
99
94
/// <returns>An <see cref="IType"/> for the <see cref="System.Type"/>.</returns>
100
95
/// <exception cref="ArgumentNullException">
101
96
/// Thrown when the <c>clazz</c> is null because the <see cref="IType"/>
102
97
/// can't be guess from a null type.
103
98
/// </exception>
104
- public static IType GuessType ( System . Type clazz , ISessionFactoryImplementor sessionFactory , out bool isCollection )
99
+ public static IType GuessType ( System . Type clazz , ISessionFactoryImplementor sessionFactory )
105
100
{
106
101
if ( clazz == null )
107
102
{
108
103
throw new ArgumentNullException ( nameof ( clazz ) , "The IType can not be guessed for a null value." ) ;
109
104
}
110
105
111
- if ( typeof ( IEnumerable ) . IsAssignableFrom ( clazz ) && typeof ( string ) != clazz )
112
- {
113
- isCollection = true ;
114
- return GuessType ( ReflectHelper . GetCollectionElementType ( clazz ) , sessionFactory ) ;
115
- }
116
-
117
- isCollection = false ;
118
- return GuessType ( clazz , sessionFactory ) ;
119
- }
120
-
121
- /// <summary>
122
- /// Guesses the <see cref="IType"/> from the <see cref="System.Type"/>.
123
- /// </summary>
124
- /// <param name="clazz">The <see cref="System.Type"/> to guess the <see cref="IType"/> of.</param>
125
- /// <param name="sessionFactory">The session factory to search for entity persister.</param>
126
- /// <returns>An <see cref="IType"/> for the <see cref="System.Type"/>.</returns>
127
- /// <exception cref="ArgumentNullException">
128
- /// Thrown when the <c>clazz</c> is null because the <see cref="IType"/>
129
- /// can't be guess from a null type.
130
- /// </exception>
131
- public static IType GuessType ( System . Type clazz , ISessionFactoryImplementor sessionFactory )
132
- {
133
106
return TryGuessType ( clazz , sessionFactory ) ??
134
107
throw new HibernateException ( "Could not determine a type for class: " + clazz . AssemblyQualifiedName ) ;
135
108
}
@@ -148,7 +121,7 @@ public static IType TryGuessType(System.Type clazz, ISessionFactoryImplementor s
148
121
{
149
122
if ( clazz == null )
150
123
{
151
- throw new ArgumentNullException ( nameof ( clazz ) , "The IType can not be guessed for a null value." ) ;
124
+ return null ;
152
125
}
153
126
154
127
var type = TypeFactory . HeuristicType ( clazz ) ;
0 commit comments