Skip to content

Commit

Permalink
Add support for any dict value type (#197)
Browse files Browse the repository at this point in the history
* Add support for any dict type

* Remove unnecessary usings
  • Loading branch information
boma96 authored Nov 5, 2024
1 parent 4a0fe5c commit 97d9dcc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/ConductorSharp.Engine/Util/ExpressionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,15 @@ private static JArray ParseListInit(ListInitExpression listInitExpression)
}

private static bool IsDictionaryInitialization(Expression expr) =>
expr is ListInitExpression listExpr && listExpr.NewExpression.Type.IsAssignableTo(typeof(IDictionary<string, object>));
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public class DictionaryInputTaskInput : IRequest<DictionaryInputTaskOutput>
{
public IDictionary<string, object> Input { get; set; }
public IDictionary<string, object> Object { get; set; }
public IDictionary<string, string> StringObject { get; set; }
public IDictionary<string, int> IntObject { get; set; }
}

public class DictionaryInputTaskOutput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -31,7 +32,9 @@ public override void BuildDefinition()
wf =>
new()
{
Input = new Dictionary<string, object>() { { "test1", "value" }, { "test2", new { MyProp = "test" } } }
Object = new Dictionary<string, object>() { { "test1", "value" }, { "test2", new { MyProp = "test" } } },
StringObject = new Dictionary<string, string>() { { "test", "test" } },
IntObject = new Dictionary<string, int>() { { "test", 1 } }
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 97d9dcc

Please sign in to comment.