Skip to content

Commit

Permalink
fix deserialization of SubmitCode.Parameters property
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Aug 8, 2024
1 parent a86ea33 commit d45e28c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ IEnumerable<KernelCommand> commands()

yield return new SubmitCode("123", "csharp");

yield return new SubmitCode("123", "csharp")
{
Parameters =
{
["SomeValue"] = "123"
}
};

yield return new UpdateDisplayedValue(
new FormattedValue("text/html", "<b>hi!</b>"),
"the-value-id");
Expand Down
25 changes: 18 additions & 7 deletions src/Microsoft.DotNet.Interactive/Commands/SubmitCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.DotNet.Interactive.Commands;

public class SubmitCode : KernelCommand
{
private Dictionary<string, string> _kernelSpecifierParameters;
private Dictionary<string, string> _parameters;

public SubmitCode(
string code,
Expand All @@ -33,10 +33,10 @@ internal SubmitCode(
{
if (directiveNode.TryGetDirective(out var directive))
{
_kernelSpecifierParameters = directiveNode.GetParameterValues(
directive,
new Dictionary<DirectiveParameterValueNode, object>())
.ToDictionary(t => t.Name, t => t.Value?.ToString());
_parameters = directiveNode.GetParameterValues(
directive,
new Dictionary<DirectiveParameterValueNode, object>())
.ToDictionary(t => t.Name, t => t.Value?.ToString());
}
}
else if (syntaxNode is DirectiveNode { Kind: DirectiveNodeKind.Action } actionDirectiveNode)
Expand All @@ -51,8 +51,19 @@ public IDictionary<string, string> Parameters
{
get
{
_kernelSpecifierParameters ??= new Dictionary<string, string>();
return _kernelSpecifierParameters;
_parameters ??= new();
return _parameters;
}
init
{
_parameters ??= new();
if (value is not null)
{
foreach (var pair in value)
{
_parameters.Add(pair.Key, pair.Value);
}
}
}
}

Expand Down

0 comments on commit d45e28c

Please sign in to comment.