Update input JSON converter to also read its ID

This commit is contained in:
Sipke Schoorstra 2023-04-25 22:39:56 +02:00
parent 876816b84c
commit cdef7d409d
3 changed files with 13 additions and 2 deletions

View file

@ -39,7 +39,7 @@ public class InputJsonConverter<T> : JsonConverter<Input<T>>
if (!expressionElement.TryGetProperty("type", out var expressionTypeNameElement))
return default!;
if (!expressionElement.TryGetProperty("value", out _))
return default!;
@ -49,10 +49,21 @@ public class InputJsonConverter<T> : JsonConverter<Input<T>>
if (expressionSyntaxDescriptor == null)
return default!;
doc.RootElement.TryGetProperty("memoryReference", out var memoryReferenceElement);
var memoryReferenceId = memoryReferenceElement.ValueKind == JsonValueKind.Undefined
? default
: memoryReferenceElement.TryGetProperty("id", out var memoryReferenceIdElement)
? memoryReferenceIdElement.GetString()
: default;
var context = new ExpressionConstructorContext(expressionElement, options);
var expression = expressionSyntaxDescriptor.CreateExpression(context);
var memoryBlockReference = expressionSyntaxDescriptor.CreateBlockReference(new BlockReferenceConstructorContext(expression));
if (memoryBlockReference.Id == null!)
memoryBlockReference.Id = memoryReferenceId!;
return (Input<T>)Activator.CreateInstance(typeof(Input<T>), expression, memoryBlockReference)!;
}

View file

@ -1,4 +1,5 @@
{
"id": "HelloWorld-v1",
"definitionId": "11e2b350dae8485498c16d1ce3843829",
"name": "Hello World",
"root": {

View file

@ -1,6 +1,5 @@
using Elsa.Extensions;
using Elsa.Testing.Shared;
using Elsa.Workflows.Core.Activities;
using Elsa.Workflows.Core.Contracts;
using Elsa.Workflows.Core.Models;
using Microsoft.Extensions.DependencyInjection;