| | | 1 | | using System.Text.Json; |
| | | 2 | | using Elsa.Expressions.Contracts; |
| | | 3 | | using Elsa.Extensions; |
| | | 4 | | |
| | | 5 | | namespace Elsa.Expressions.Models; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Describes an expression type. |
| | | 9 | | /// </summary> |
| | | 10 | | public class ExpressionDescriptor |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Initializes a new instance of the <see cref="ExpressionDescriptor"/> class. |
| | | 14 | | /// </summary> |
| | 31 | 15 | | public ExpressionDescriptor() |
| | | 16 | | { |
| | | 17 | | // Default deserialization function. |
| | 31 | 18 | | Deserialize = context => |
| | 31 | 19 | | { |
| | 305 | 20 | | var expression = new Expression(context.ExpressionType, null); |
| | 31 | 21 | | |
| | 305 | 22 | | if (context.JsonElement.ValueKind == JsonValueKind.Object) |
| | 305 | 23 | | if (context.JsonElement.TryGetProperty("value", out var expressionValueElement)) |
| | 305 | 24 | | expression.Value = expressionValueElement.GetValue(); |
| | 31 | 25 | | |
| | 305 | 26 | | return expression; |
| | 31 | 27 | | }; |
| | 31 | 28 | | } |
| | | 29 | | |
| | | 30 | | /// <summary> |
| | | 31 | | /// Gets or sets the syntax name. |
| | | 32 | | /// </summary> |
| | 62 | 33 | | public string Type { get; init; } = default!; |
| | | 34 | | |
| | | 35 | | /// <summary> |
| | | 36 | | /// Gets or sets the display name of the expression type. |
| | | 37 | | /// </summary> |
| | 28 | 38 | | public string DisplayName { get; set; } = default!; |
| | | 39 | | |
| | | 40 | | /// <summary> |
| | | 41 | | /// Gets or sets whether the expression value is serializable. |
| | | 42 | | /// </summary> |
| | 3094 | 43 | | public bool IsSerializable { get; set; } = true; |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Gets or sets whether the expression type is browsable. |
| | | 47 | | /// </summary> |
| | 55 | 48 | | public bool IsBrowsable { get; set; } = true; |
| | | 49 | | |
| | | 50 | | /// <summary> |
| | | 51 | | /// Gets or sets the expression type properties. |
| | | 52 | | /// </summary> |
| | 43 | 53 | | public IDictionary<string, object> Properties { get; set; } = new Dictionary<string, object>(); |
| | | 54 | | |
| | | 55 | | /// <summary> |
| | | 56 | | /// Gets or sets the expression handler factory. |
| | | 57 | | /// </summary> |
| | 1607 | 58 | | public Func<IServiceProvider, IExpressionHandler> HandlerFactory { get; set; } = default!; |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Gets or sets the memory block reference factory. |
| | | 62 | | /// </summary> |
| | 2088 | 63 | | public Func<MemoryBlockReference> MemoryBlockReferenceFactory { get; set; } = () => new MemoryBlockReference(); |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Gets or sets the expression deserialization function. |
| | | 67 | | /// </summary> |
| | 2034 | 68 | | public Func<ExpressionSerializationContext, Expression> Deserialize { get; set; } = default!; |
| | | 69 | | } |