From 80d3e1cdb0b3724689afc809d065d4f99b7621ff Mon Sep 17 00:00:00 2001 From: "bojan.malinic" Date: Tue, 5 Nov 2024 09:49:00 +0100 Subject: [PATCH 1/2] Add support for any dict type --- src/ConductorSharp.Engine/Util/ExpressionUtil.cs | 12 +++++++++++- .../Samples/Tasks/DictionaryInputTask.cs | 4 +++- .../Workflows/DictionaryInitializationWorkflow.cs | 5 ++++- .../Workflows/DictionaryInitializationWorkflow.json | 8 +++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/ConductorSharp.Engine/Util/ExpressionUtil.cs b/src/ConductorSharp.Engine/Util/ExpressionUtil.cs index ff46061..2d8639e 100644 --- a/src/ConductorSharp.Engine/Util/ExpressionUtil.cs +++ b/src/ConductorSharp.Engine/Util/ExpressionUtil.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -7,6 +8,7 @@ using ConductorSharp.Engine.Exceptions; using ConductorSharp.Engine.Interface; using Newtonsoft.Json.Linq; +using ListInitExpression = System.Linq.Expressions.ListInitExpression; namespace ConductorSharp.Engine.Util { @@ -192,7 +194,15 @@ private static JArray ParseListInit(ListInitExpression listInitExpression) } private static bool IsDictionaryInitialization(Expression expr) => - expr is ListInitExpression listExpr && listExpr.NewExpression.Type.IsAssignableTo(typeof(IDictionary)); + expr is ListInitExpression listExpr + && listExpr + .NewExpression.Type.GetInterfaces() + .Any( + iface => + iface.IsGenericType + && iface.GetGenericTypeDefinition() == typeof(IDictionary<,>) + && iface.GenericTypeArguments[0] == typeof(string) + ); private static JObject ParseDictionaryInitialization(ListInitExpression listExpression) { diff --git a/test/ConductorSharp.Engine.Tests/Samples/Tasks/DictionaryInputTask.cs b/test/ConductorSharp.Engine.Tests/Samples/Tasks/DictionaryInputTask.cs index d2f2304..3bdec65 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Tasks/DictionaryInputTask.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Tasks/DictionaryInputTask.cs @@ -2,7 +2,9 @@ public class DictionaryInputTaskInput : IRequest { - public IDictionary Input { get; set; } + public IDictionary Object { get; set; } + public IDictionary StringObject { get; set; } + public IDictionary IntObject { get; set; } } public class DictionaryInputTaskOutput; diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/DictionaryInitializationWorkflow.cs b/test/ConductorSharp.Engine.Tests/Samples/Workflows/DictionaryInitializationWorkflow.cs index 6c68aed..f02672f 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/DictionaryInitializationWorkflow.cs +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/DictionaryInitializationWorkflow.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json.Nodes; using System.Threading.Tasks; namespace ConductorSharp.Engine.Tests.Samples.Workflows @@ -31,7 +32,9 @@ public override void BuildDefinition() wf => new() { - Input = new Dictionary() { { "test1", "value" }, { "test2", new { MyProp = "test" } } } + Object = new Dictionary() { { "test1", "value" }, { "test2", new { MyProp = "test" } } }, + StringObject = new Dictionary() { { "test", "test" } }, + IntObject = new Dictionary() { { "test", 1 } } } ); } diff --git a/test/ConductorSharp.Engine.Tests/Samples/Workflows/DictionaryInitializationWorkflow.json b/test/ConductorSharp.Engine.Tests/Samples/Workflows/DictionaryInitializationWorkflow.json index e539515..a32c027 100644 --- a/test/ConductorSharp.Engine.Tests/Samples/Workflows/DictionaryInitializationWorkflow.json +++ b/test/ConductorSharp.Engine.Tests/Samples/Workflows/DictionaryInitializationWorkflow.json @@ -6,11 +6,17 @@ "name": "dictionary_input_task", "taskReferenceName": "dictionary_task", "inputParameters": { - "input": { + "object": { "test1": "value", "test2": { "my_prop": "test" } + }, + "string_object": { + "test": "test" + }, + "int_object": { + "test": 1 } }, "type": "SIMPLE", From 3b9b52cca397042204671ba0e914bbaa3afe964b Mon Sep 17 00:00:00 2001 From: "bojan.malinic" Date: Tue, 5 Nov 2024 09:50:47 +0100 Subject: [PATCH 2/2] Remove unnecessary usings --- src/ConductorSharp.Engine/Util/ExpressionUtil.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/ConductorSharp.Engine/Util/ExpressionUtil.cs b/src/ConductorSharp.Engine/Util/ExpressionUtil.cs index 2d8639e..b93b127 100644 --- a/src/ConductorSharp.Engine/Util/ExpressionUtil.cs +++ b/src/ConductorSharp.Engine/Util/ExpressionUtil.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -8,7 +7,6 @@ using ConductorSharp.Engine.Exceptions; using ConductorSharp.Engine.Interface; using Newtonsoft.Json.Linq; -using ListInitExpression = System.Linq.Expressions.ListInitExpression; namespace ConductorSharp.Engine.Util {