1111using System . Reflection ;
1212using JetBrains . Annotations ;
1313using System . Linq . Dynamic . Core . Parser ;
14+ using System . Text ;
15+
1416#if WINDOWS_APP
1517using System ;
1618using System . Linq ;
@@ -28,7 +30,6 @@ public static class DynamicQueryableExtensions
2830#if ! ( WINDOWS_APP45x || SILVERLIGHT )
2931 private static readonly TraceSource TraceSource = new TraceSource ( typeof ( DynamicQueryableExtensions ) . Name ) ;
3032#endif
31- private static readonly Func < MethodInfo , bool > PredicateParameterHas2 = mi => mi . GetParameters ( ) [ 1 ] . ToString ( ) . Contains ( "Func`2" ) ;
3233
3334 private static Expression OptimizeExpression ( Expression expression )
3435 {
@@ -1635,7 +1636,16 @@ public static IQueryable Skip([NotNull] this IQueryable source, int count)
16351636 #endregion Skip
16361637
16371638 #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+ } ) ;
16391649
16401650 /// <summary>
16411651 /// 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)
17041714 #endregion Take
17051715
17061716 #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+ } ) ;
17081727
17091728 /// <summary>
17101729 /// 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
20162035 }
20172036 catch ( Exception ex )
20182037 {
2019- TraceSource . TraceEvent ( TraceEventType . Error , 0 , "Method not found: {0} - {1}" , name , ex ) ;
2038+ throw new Exception ( "Method not found: " + name , ex ) ;
20202039 }
2021-
2022- return null ;
20232040 }
20242041 #endregion Private Helpers
20252042 }
0 commit comments