-
-
Notifications
You must be signed in to change notification settings - Fork 722
/
StringOperationHandlerBase.cs
47 lines (41 loc) · 1.4 KB
/
StringOperationHandlerBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Diagnostics.CodeAnalysis;
using System.Linq.Expressions;
using HotChocolate.Language;
namespace HotChocolate.Types.Filters.Expressions
{
public abstract class StringOperationHandlerBase
: IExpressionOperationHandler
{
public bool TryHandle(
FilterOperation operation,
IInputType type,
IValueNode value,
IQueryableFilterVisitorContext context,
[NotNullWhen(true)] out Expression? expression)
{
if (operation.Type == typeof(string) &&
type.IsInstanceOfType(value))
{
object? parsedValue = type.ParseLiteral(value);
Expression property = context.GetInstance();
if (!operation.IsSimpleArrayType())
{
property = Expression.Property(
context.GetInstance(), operation.Property);
}
return TryCreateExpression(
operation,
property,
parsedValue,
out expression);
}
expression = null;
return false;
}
protected abstract bool TryCreateExpression(
FilterOperation operation,
Expression property,
object parsedValue,
[NotNullWhen(true)] out Expression? expression);
}
}