11
11
using System . Reflection ;
12
12
using JetBrains . Annotations ;
13
13
using System . Linq . Dynamic . Core . Parser ;
14
+ using System . Text ;
15
+
14
16
#if WINDOWS_APP
15
17
using System ;
16
18
using System . Linq ;
@@ -28,7 +30,6 @@ public static class DynamicQueryableExtensions
28
30
#if ! ( WINDOWS_APP45x || SILVERLIGHT )
29
31
private static readonly TraceSource TraceSource = new TraceSource ( typeof ( DynamicQueryableExtensions ) . Name ) ;
30
32
#endif
31
- private static readonly Func < MethodInfo , bool > PredicateParameterHas2 = mi => mi . GetParameters ( ) [ 1 ] . ToString ( ) . Contains ( "Func`2" ) ;
32
33
33
34
private static Expression OptimizeExpression ( Expression expression )
34
35
{
@@ -1635,7 +1636,16 @@ public static IQueryable Skip([NotNull] this IQueryable source, int count)
1635
1636
#endregion Skip
1636
1637
1637
1638
#region SkipWhile
1638
- private static readonly MethodInfo _skipWhilePredicate = GetMethod ( nameof ( Queryable . SkipWhile ) , 1 , PredicateParameterHas2 ) ;
1639
+
1640
+ private static readonly MethodInfo _skipWhilePredicate = GetMethod ( nameof ( Queryable . SkipWhile ) , 1 , mi =>
1641
+ {
1642
+ return mi . GetParameters ( ) . Length == 1 &&
1643
+ mi . GetParameters ( ) [ 1 ] . ParameterType . GetTypeInfo ( ) . IsGenericType &&
1644
+ mi . GetParameters ( ) [ 1 ] . ParameterType . GetGenericTypeDefinition ( ) == typeof ( Expression < > ) &&
1645
+ mi . GetParameters ( ) [ 1 ] . ParameterType . GetGenericArguments ( ) [ 0 ] . GetTypeInfo ( ) . IsGenericType &&
1646
+ mi . GetParameters ( ) [ 1 ] . ParameterType . GetGenericArguments ( ) [ 0 ] . GetGenericTypeDefinition ( ) ==
1647
+ typeof ( Func < , > ) ;
1648
+ } ) ;
1639
1649
1640
1650
/// <summary>
1641
1651
/// Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.
@@ -1704,7 +1714,16 @@ public static IQueryable Take([NotNull] this IQueryable source, int count)
1704
1714
#endregion Take
1705
1715
1706
1716
#region TakeWhile
1707
- private static readonly MethodInfo _takeWhilePredicate = GetMethod ( nameof ( Queryable . TakeWhile ) , 1 , PredicateParameterHas2 ) ;
1717
+
1718
+ private static readonly MethodInfo _takeWhilePredicate = GetMethod ( nameof ( Queryable . TakeWhile ) , 1 , mi =>
1719
+ {
1720
+ return mi . GetParameters ( ) . Length == 1 &&
1721
+ mi . GetParameters ( ) [ 1 ] . ParameterType . GetTypeInfo ( ) . IsGenericType &&
1722
+ mi . GetParameters ( ) [ 1 ] . ParameterType . GetGenericTypeDefinition ( ) == typeof ( Expression < > ) &&
1723
+ mi . GetParameters ( ) [ 1 ] . ParameterType . GetGenericArguments ( ) [ 0 ] . GetTypeInfo ( ) . IsGenericType &&
1724
+ mi . GetParameters ( ) [ 1 ] . ParameterType . GetGenericArguments ( ) [ 0 ] . GetGenericTypeDefinition ( ) ==
1725
+ typeof ( Func < , > ) ;
1726
+ } ) ;
1708
1727
1709
1728
/// <summary>
1710
1729
/// Returns elements from a sequence as long as a specified condition is true.
@@ -2016,10 +2035,8 @@ private static MethodInfo GetMethod(string name, int parameterCount = 0, Func<Me
2016
2035
}
2017
2036
catch ( Exception ex )
2018
2037
{
2019
- TraceSource . TraceEvent ( TraceEventType . Error , 0 , "Method not found: {0} - {1}" , name , ex ) ;
2038
+ throw new Exception ( "Method not found: " + name , ex ) ;
2020
2039
}
2021
-
2022
- return null ;
2023
2040
}
2024
2041
#endregion Private Helpers
2025
2042
}
0 commit comments