From 3f862f413758bb2092ff54ed12f5b5aaf9ed72bf Mon Sep 17 00:00:00 2001 From: tomy2105 Date: Wed, 23 Jun 2021 16:04:55 +0200 Subject: [PATCH] State sets default value if get doesn't find it Which allows for normal usage of Dictionaries inside state.... --- .../Extensions/StateDictionaryExtensions.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/core/Elsa.Abstractions/Extensions/StateDictionaryExtensions.cs b/src/core/Elsa.Abstractions/Extensions/StateDictionaryExtensions.cs index 1df6db8f7..fed252ca5 100644 --- a/src/core/Elsa.Abstractions/Extensions/StateDictionaryExtensions.cs +++ b/src/core/Elsa.Abstractions/Extensions/StateDictionaryExtensions.cs @@ -16,8 +16,16 @@ namespace Elsa { var item = state?.ContainsKey(key) == true ? state![key] : default; - if (item == null) - return defaultValue(); + if (item == null) + { + if (state != null) + { + state.SetState(key, defaultValue()); + item = state![key]; + } + else + return defaultValue(); + } return item.ConvertTo()!; }