elsa-core/src/modules/Elsa.ProtoActor/Extensions/ProtoInputExtensions.cs

32 lines
929 B
C#
Raw Normal View History

2022-03-04 18:59:44 +00:00
using System.Text.Json;
using Elsa.ProtoActor.ProtoBuf;
using Elsa.Workflows.Core.Serialization.Converters;
2022-03-04 18:59:44 +00:00
namespace Elsa.ProtoActor.Extensions;
2022-03-04 18:59:44 +00:00
internal static class ProtoInputExtensions
2022-03-04 18:59:44 +00:00
{
public static IDictionary<string, object> Deserialize(this Input input)
{
var jsonSerializerOptions = new JsonSerializerOptions();
jsonSerializerOptions.Converters.Add(new ExpandoObjectConverterFactory());
return input.Data.ToDictionary(x => x.Key, x => JsonSerializer.Deserialize<object>(x.Value.Text, jsonSerializerOptions)!);
}
2022-03-04 18:59:44 +00:00
public static Input Serialize(this IDictionary<string, object> input)
2022-03-04 18:59:44 +00:00
{
var result = new Input();
var data = result.Data;
foreach (var (key, value) in input)
{
data[key] = new Json
2022-03-04 18:59:44 +00:00
{
Text = JsonSerializer.Serialize(value)
};
}
return result;
}
}