diff --git a/src/clients/Elsa.Api.Client/Extensions/DictionaryExtensions.cs b/src/clients/Elsa.Api.Client/Extensions/DictionaryExtensions.cs index 3a82775e1..e7a3b8f74 100644 --- a/src/clients/Elsa.Api.Client/Extensions/DictionaryExtensions.cs +++ b/src/clients/Elsa.Api.Client/Extensions/DictionaryExtensions.cs @@ -12,9 +12,14 @@ public static class DictionaryExtensions /// public static T? TryGetValue(this IDictionary dictionary, string key, Func? defaultValue = default, JsonSerializerOptions? serializerOptions = default) { - if (dictionary.TryGetValue(key, out var value) && value is not JsonElement { ValueKind: JsonValueKind.Undefined }) - return value.ConvertTo(new ObjectConverterOptions(serializerOptions)); - + if (dictionary.TryGetValue(key, out var value) && value is not JsonElement { ValueKind: JsonValueKind.Undefined }) + { + var convertedValue = value.ConvertTo(new ObjectConverterOptions(serializerOptions)); + + if (convertedValue != null) + return convertedValue; + } + if (defaultValue == null) return default; @@ -22,15 +27,15 @@ public static class DictionaryExtensions dictionary[key] = defaultVal; return defaultVal; } - + /// /// Returns the value of the specified property if it exists, otherwise the default value. /// public static object? TryGetValue(this IDictionary dictionary, string key, Func? defaultValue = default) { - if (dictionary.TryGetValue(key, out var value) && value is not JsonElement { ValueKind: JsonValueKind.Undefined }) + if (dictionary.TryGetValue(key, out var value) && value is not JsonElement { ValueKind: JsonValueKind.Undefined }) return value; - + if (defaultValue == null) return default;