Skip to content

Commit 465b73e

Browse files
NH-4027 - Getting rid of an old non generic enumerator by moving to generic.
1 parent 2e1ea9c commit 465b73e

File tree

4 files changed

+16
-55
lines changed

4 files changed

+16
-55
lines changed

src/NHibernate/IFilter.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections;
2+
using System.Collections.Generic;
23
using NHibernate.Engine;
34

45
namespace NHibernate
@@ -10,7 +11,7 @@ namespace NHibernate
1011
public interface IFilter
1112
{
1213
/// <summary>
13-
/// Get the name of this filter.
14+
/// Get the name of this filter.
1415
/// </summary>
1516
/// <returns>This filter's name.</returns>
1617
string Name { get; }
@@ -23,34 +24,26 @@ public interface IFilter
2324
FilterDefinition FilterDefinition { get; }
2425

2526
/// <summary>
26-
/// Set the named parameter's value list for this filter.
27+
/// Set the named parameter's value list for this filter.
2728
/// </summary>
2829
/// <param name="name">The parameter's name.</param>
2930
/// <param name="value">The values to be applied.</param>
3031
/// <returns>This FilterImpl instance (for method chaining).</returns>
3132
IFilter SetParameter(string name, object value);
3233

3334
/// <summary>
34-
/// Set the named parameter's value list for this filter. Used
35-
/// in conjunction with IN-style filter criteria.
35+
/// Set the named parameter's value list for this filter. Used
36+
/// in conjunction with IN-style filter criteria.
3637
/// </summary>
3738
/// <param name="name">The parameter's name.</param>
3839
/// <param name="values">The values to be expanded into an SQL IN list.</param>
40+
/// <typeparam name="T">The type of the values.</typeparam>
3941
/// <returns>This FilterImpl instance (for method chaining).</returns>
40-
IFilter SetParameterList(string name, ICollection values);
41-
42-
/// <summary>
43-
/// Set the named parameter's value list for this filter. Used
44-
/// in conjunction with IN-style filter criteria.
45-
/// </summary>
46-
/// <param name="name">The parameter's name.</param>
47-
/// <param name="values">The values to be expanded into an SQL IN list.</param>
48-
/// <returns>This FilterImpl instance (for method chaining).</returns>
49-
IFilter SetParameterList(string name, object[] values);
42+
IFilter SetParameterList<T>(string name, ICollection<T> values);
5043

5144
/// <summary>
5245
/// Perform validation of the filter state. This is used to verify the
53-
/// state of the filter after its enablement and before its use.
46+
/// state of the filter after its activation and before its use.
5447
/// </summary>
5548
/// <returns></returns>
5649
void Validate();

src/NHibernate/Impl/EnumerableImpl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ namespace NHibernate.Impl
1717
/// <remarks>
1818
/// <para>This is the IteratorImpl in H2.0.3</para>
1919
/// <para>This thing is scary. It is an <see cref="IEnumerable" /> which returns itself as a <see cref="IEnumerator" />
20-
/// when <c>GetEnumerator</c> is called, and EnumerableImpl is disposable. Iterating over it with a <c>foreach</c>
21-
/// will cause it to be disposed, probably unexpectedly. (https://stackoverflow.com/a/11179175/1178314)
20+
/// when <c>GetEnumerator</c> is called, and <c>EnumerableImpl</c> is disposable. Iterating over it with a <c>foreach</c>
21+
/// will cause it to be disposed, probably unexpectedly for the developer. (https://stackoverflow.com/a/11179175/1178314)
2222
/// "Fortunately", it does not currently support multiple iterations anyway.</para>
2323
/// </remarks>
2424
public class EnumerableImpl : IEnumerable, IEnumerator, IDisposable

src/NHibernate/Impl/FilterImpl.cs

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections;
32
using NHibernate.Engine;
43
using NHibernate.Type;
54
using System.Collections.Generic;
@@ -76,52 +75,21 @@ public IFilter SetParameter(string name, object value)
7675
/// <param name="name">The parameter's name.</param>
7776
/// <param name="values">The values to be expanded into an SQL IN list.</param>
7877
/// <returns>This FilterImpl instance (for method chaining).</returns>
79-
public IFilter SetParameterList(string name, ICollection values)
78+
public IFilter SetParameterList<T>(string name, ICollection<T> values)
8079
{
81-
// Make sure this is a defined parameter and check the incoming value type
82-
if (values == null)
83-
{
84-
throw new ArgumentException("Collection must be not null!", "values");
85-
}
86-
8780
var type = definition.GetParameterType(name);
8881
if (type == null)
8982
{
9083
throw new HibernateException("Undefined filter parameter [" + name + "]");
9184
}
9285

93-
if (values.Count > 0)
86+
if (!type.ReturnedClass.IsAssignableFrom(typeof(T)))
9487
{
95-
var e = values.GetEnumerator();
96-
try
97-
{
98-
e.MoveNext();
99-
if (!type.ReturnedClass.IsInstanceOfType(e.Current))
100-
{
101-
throw new HibernateException("Incorrect type for parameter [" + name + "]");
102-
}
103-
}
104-
finally
105-
{
106-
// Most enumerators are indeed disposable. foreach takes care of disposing them, but
107-
// when using them directly, we have to do it.
108-
(e as IDisposable)?.Dispose();
109-
}
88+
throw new HibernateException("Incorrect type for parameter [" + name + "]");
11089
}
111-
parameters[name] = values;
112-
return this;
113-
}
11490

115-
/// <summary>
116-
/// Set the named parameter's value list for this filter. Used
117-
/// in conjunction with IN-style filter criteria.
118-
/// </summary>
119-
/// <param name="name">The parameter's name.</param>
120-
/// <param name="values">The values to be expanded into an SQL IN list.</param>
121-
/// <returns>This FilterImpl instance (for method chaining).</returns>
122-
public IFilter SetParameterList(string name, object[] values)
123-
{
124-
return SetParameterList(name, new List<object>(values));
91+
parameters[name] = values ?? throw new ArgumentException("Collection must be not null!", nameof(values));
92+
return this;
12593
}
12694

12795
public object GetParameter(string name)

src/NHibernate/Mapping/SimpleValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2-
using System.Collections;
32
using System.Collections.Generic;
3+
using System.Linq;
44
using System.Text;
55
using NHibernate.Engine;
66
using NHibernate.Id;

0 commit comments

Comments
 (0)