Skip to content

Commit

Permalink
Improved output for List<object?>
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnmbond committed Mar 25, 2024
1 parent 7332ffc commit 471ec33
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions PanoramicData.NCalc101/Components/Pages/Home.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,15 @@ private async Task EvaluateAsync()
_result = output switch
{
null => "null",
List<object?> => string.Join("\r\n", (output as List<object?>)!.Select(ob => ob?.ToString() ?? "null")),
List<string> => string.Join("\r\n", output as List<string> ?? []),
_ => output.ToString()
} ?? string.Empty;
_resultType = output switch
{
null => "null",
List<string> => "List<string>",
List<object?> => "List<object?>",
_ => output.GetType().ToString()
};
}
Expand Down
6 changes: 5 additions & 1 deletion PanoramicData.NCalc101/Examples/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ private void EvaluateIfRequired()

_result = expression.Evaluate();
_resultTypeString = _result is null ? "null" : _result.GetType().ToString();
_resultAsString = _result?.ToString() ?? string.Empty;
_resultAsString = _resultTypeString switch
{
"System.Collections.Generic.List`1[System.Object]" => string.Join("\n", (_result as List<object?>)!.Select(ob => ob?.ToString() ?? "null")),
_ => _result?.ToString() ?? "null"
};
}
catch (Exception ex)
{
Expand Down

0 comments on commit 471ec33

Please sign in to comment.