forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSafetyEnumerable.cs
41 lines (37 loc) · 953 Bytes
/
SafetyEnumerable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
using System.Collections;
using System.Collections.Generic;
namespace NHibernate.Util
{
/// <summary>
/// Used to ensure a collection filtering a given IEnumerable by a certain type.
/// </summary>
/// <typeparam name="T">The type used like filter.</typeparam>
// Since v5.3
[Obsolete("This class has no more usages and will be removed in a future version")]
public class SafetyEnumerable<T> : IEnumerable<T>
{
/*
* This class was created to filter List<ISelectable> to an IEnumerable<Column>
*/
private readonly IEnumerable _collection;
public SafetyEnumerable(IEnumerable collection)
{
_collection = collection;
}
public IEnumerator<T> GetEnumerator()
{
foreach (var element in _collection)
{
if (element == null)
yield return default(T);
else if (element is T elem)
yield return elem;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}