Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for any dict value type #197

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading