/// <exception cref="NotSupportedException" /> /// <exception cref="InvalidOperationException" /> private IEnumerable <T> FilterComparsion( Expression memberExpression, Expression keyExpression, ExpressionType type) { IComparsionIndex <T> index = FindComparsionIndex(memberExpression); object key = keyExpression.GetValue(); switch (type) { case ExpressionType.GreaterThan: return(index.GreaterThan(key, exclusive: true)); case ExpressionType.GreaterThanOrEqual: return(index.GreaterThan(key, exclusive: false)); case ExpressionType.LessThan: return(index.LessThan(key, exclusive: true)); case ExpressionType.LessThanOrEqual: return(index.LessThan(key, exclusive: false)); default: throw new NotSupportedException($"Expression {type} should be Comparsion"); } }
/// <exception cref="NotSupportedException" /> /// <exception cref="InvalidOperationException" /> private IEnumerable <T> FilterStringStartsWith(MethodCallExpression methodCall) { if (methodCall.Method.DeclaringType == typeof(String) && methodCall.Method.Name == nameof(String.StartsWith)) { IComparsionIndex <T> index = FindComparsionIndex(methodCall.Object); string keyFrom = (string)methodCall.Arguments.First().GetValue(); if (String.IsNullOrEmpty(keyFrom)) { return(index.GreaterThan(keyFrom, false)); } char lastChar = keyFrom[keyFrom.Length - 1]; string keyTo = keyFrom.Substring(0, keyFrom.Length - 1) + (char)(lastChar + 1); return(index.Between(keyFrom, false, keyTo, true)); } throw new NotSupportedException( $"Predicate body {methodCall} should be String.StartsWith()"); }