| | | 1 | | using Elsa.Expressions.Contracts; |
| | | 2 | | using Elsa.Expressions.Models; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Expressions.Services; |
| | | 5 | | |
| | | 6 | | /// <inheritdoc /> |
| | 327 | 7 | | public class ExpressionEvaluator(IExpressionDescriptorRegistry registry, IServiceProvider serviceProvider) : IExpression |
| | | 8 | | { |
| | | 9 | | /// <inheritdoc /> |
| | | 10 | | public async ValueTask<T?> EvaluateAsync<T>(Expression expression, ExpressionExecutionContext context, ExpressionEva |
| | | 11 | | { |
| | 8 | 12 | | return (T?)await EvaluateAsync(expression, typeof(T), context, options); |
| | 6 | 13 | | } |
| | | 14 | | |
| | | 15 | | /// <inheritdoc /> |
| | | 16 | | public async ValueTask<object?> EvaluateAsync(Expression expression, Type returnType, ExpressionExecutionContext con |
| | | 17 | | { |
| | 1577 | 18 | | var expressionType = expression.Type; |
| | 1577 | 19 | | var expressionDescriptor = registry.Find(expressionType); |
| | | 20 | | |
| | 1577 | 21 | | if (expressionDescriptor == null) |
| | 1 | 22 | | throw new($"Could not find a descriptor for expression type \"{expressionType}\"."); |
| | | 23 | | |
| | 1576 | 24 | | var handler = expressionDescriptor.HandlerFactory(serviceProvider); |
| | 1576 | 25 | | options ??= new(); |
| | 1576 | 26 | | return await handler.EvaluateAsync(expression, returnType, context, options); |
| | 1575 | 27 | | } |
| | | 28 | | } |