Fix property handling

This commit is contained in:
Sipke Schoorstra 2022-12-16 21:10:18 +01:00
parent bc0bca2f51
commit b10d91b525
2 changed files with 3 additions and 2 deletions

View file

@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using Elsa.Common.Extensions;
using Elsa.Expressions.Helpers;
using Elsa.Expressions.Models;
using Elsa.Workflows.Core.Services;
using Microsoft.Extensions.DependencyInjection;
@ -137,7 +138,7 @@ public class WorkflowExecutionContext
public ActivityNode FindNodeById(string nodeId) => NodeIdLookup[nodeId];
public ActivityNode FindNodeByActivity(IActivity activity) => NodeActivityLookup[activity];
public IActivity FindActivityById(string activityId) => FindNodeById(activityId).Activity;
public T? GetProperty<T>(string key) => Properties.TryGetValue(key, out var value) ? (T?)value : default(T);
public T? GetProperty<T>(string key) => Properties.TryGetValue(key, out var value) ? value.ConvertTo<T>() : default;
public void SetProperty<T>(string key, T value) => Properties[key] = value!;
public T UpdateProperty<T>(string key, Func<T?, T> updater)

View file

@ -6,7 +6,7 @@ namespace Elsa.Workflows.Core.Serialization.Converters;
public class PropertyBagConverter : JsonConverter<PropertyBag>
{
public override PropertyBag? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
public override PropertyBag Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var dictionary = JsonSerializer.Deserialize<Dictionary<string, object>>(ref reader);
return new PropertyBag(dictionary);