public static bool NotStartsWith( FilterOperation operation, IInputType type, IValueNode value, IQueryableFilterVisitorContext context, [NotNullWhen(true)] out Expression?result) { object parsedValue = type.ParseLiteral(value); if (parsedValue == null) { context.ReportError( ErrorHelper.CreateNonNullError(operation, type, value, context)); result = null; return(false); } if (operation.Type == typeof(string) && type.IsInstanceOfType(value)) { Expression property = GetProperty(operation, context); result = FilterExpressionBuilder.Not( FilterExpressionBuilder.StartsWith(property, parsedValue)); return(true); } else { throw new InvalidOperationException(); } }
public bool TryHandle( FilterOperation operation, IInputType type, IValueNode value, Expression instance, ITypeConversion converter, out Expression expression) { if (operation.Type == typeof(string) && value is StringValueNode s) { MemberExpression property = Expression.Property(instance, operation.Property); switch (operation.Kind) { case FilterOperationKind.Equals: expression = FilterExpressionBuilder.Equals( property, s.Value); return(true); case FilterOperationKind.NotEquals: expression = FilterExpressionBuilder.Not( FilterExpressionBuilder.Equals(property, s.Value) ); return(true); case FilterOperationKind.StartsWith: expression = FilterExpressionBuilder.StartsWith( property, s.Value); return(true); case FilterOperationKind.EndsWith: expression = FilterExpressionBuilder.EndsWith( property, s.Value); return(true); case FilterOperationKind.NotStartsWith: expression = FilterExpressionBuilder.Not( FilterExpressionBuilder.StartsWith( property, s.Value) ); return(true); case FilterOperationKind.NotEndsWith: expression = FilterExpressionBuilder.Not( FilterExpressionBuilder.EndsWith(property, s.Value) ); return(true); case FilterOperationKind.Contains: expression = FilterExpressionBuilder.Contains( property, s.Value); return(true); case FilterOperationKind.NotContains: expression = FilterExpressionBuilder.Not( FilterExpressionBuilder.Contains(property, s.Value) ); return(true); } } if (operation.Type == typeof(string) && value is ListValueNode li) { MemberExpression property = Expression.Property(instance, operation.Property); var parsedValue = type.ParseLiteral(value); switch (operation.Kind) { case FilterOperationKind.In: expression = FilterExpressionBuilder.In( property, operation.Property.PropertyType, parsedValue); return(true); case FilterOperationKind.NotIn: expression = FilterExpressionBuilder.Not( FilterExpressionBuilder.In( property, operation.Property.PropertyType, parsedValue)); return(true); } } expression = null; return(false); }