Skip to content

Commit 82a16f4

Browse files
committed
Reinstating .None(IEnumerable<T>) method to fix dictionary mapping
1 parent 56e8207 commit 82a16f4

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

AgileMapper/DataSources/DictionaryEntryVariablePair.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ internal class DictionaryEntryVariablePair
1818
.First(m => (m.Name == "FirstOrDefault") && (m.GetParameters().Length == 2))
1919
.MakeGenericMethod(typeof(string));
2020

21-
private static readonly MethodInfo _enumerableNoneMethod = typeof(EnumerableExtensions)
22-
.GetPublicStaticMethods()
23-
.First(m => (m.Name == "None") && (m.GetParameters().Length == 2))
24-
.MakeGenericMethod(typeof(string));
25-
2621
private static readonly MethodInfo _stringStartsWithMethod = typeof(string)
2722
.GetPublicInstanceMethods()
2823
.First(m => (m.Name == "StartsWith") && (m.GetParameters().Length == 2));
@@ -134,7 +129,7 @@ public Expression GetNoKeysWithMatchingStartQuery(Expression targetMemberKey)
134129
targetMemberKey,
135130
(keyParameter, targetKey) => GetKeyStartsWithCall(keyParameter, targetKey, StringComparison.Ordinal),
136131
(keyParameter, targetKey) => GetKeyStartsWithCall(keyParameter, targetKey, StringComparison.OrdinalIgnoreCase),
137-
_enumerableNoneMethod);
132+
EnumerableExtensions.EnumerableNoneMethod);
138133

139134
return noKeysStartWithTarget;
140135
}

AgileMapper/Extensions/EnumerableExtensions.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55
using System.Diagnostics;
66
using System.Linq;
77
using System.Linq.Expressions;
8+
using System.Reflection;
9+
using NetStandardPolyfills;
810

911
internal static class EnumerableExtensions
1012
{
13+
public static readonly MethodInfo EnumerableNoneMethod = typeof(EnumerableExtensions)
14+
.GetPublicStaticMethods()
15+
.First(m => (m.Name == "None") && (m.GetParameters().Length == 2))
16+
.MakeGenericMethod(typeof(string));
17+
1118
public static void AddUnlessNullOrEmpty(this ICollection<Expression> items, Expression item)
1219
{
1320
if ((item != null) && (item != Constants.EmptyExpression))
@@ -43,6 +50,11 @@ public static T First<T>(this IList<T> items, Func<T, bool> predicate)
4350
[DebuggerStepThrough]
4451
public static bool None<T>(this ICollection<T> items) => items.Count == 0;
4552

53+
public static bool None<T>(this IEnumerable<T> items, Func<T, bool> predicate)
54+
{
55+
return items.All(item => !predicate.Invoke(item));
56+
}
57+
4658
public static bool None<T>(this IList<T> items, Func<T, bool> predicate)
4759
{
4860
for (int i = 0, n = items.Count; i < n; i++)

0 commit comments

Comments
 (0)