feat(scripts): add typed Parameters.Get<T>() helpers for script API

Replace raw dictionary casting with ScriptParameters wrapper that provides
Get<T>, Get<T?>, Get<T[]>, and Get<List<T>> with clear error messages,
numeric conversion, and JsonElement support for Inbound API parameters.
This commit is contained in:
Joseph Doherty
2026-03-22 15:47:18 -04:00
parent a0e036fb6b
commit 161dc406ed
10 changed files with 672 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ using Microsoft.CodeAnalysis.CSharp.Scripting;
using Microsoft.CodeAnalysis.Scripting;
using Microsoft.Extensions.Logging;
using ScadaLink.Commons.Entities.InboundApi;
using ScadaLink.Commons.Types;
namespace ScadaLink.InboundAPI;
@@ -58,6 +59,7 @@ public class InboundScriptExecutor
typeof(Enumerable).Assembly,
typeof(Dictionary<,>).Assembly,
typeof(RouteHelper).Assembly,
typeof(ScriptParameters).Assembly,
typeof(Microsoft.CSharp.RuntimeBinder.CSharpArgumentInfo).Assembly)
.WithImports(
"System",
@@ -152,7 +154,7 @@ public class InboundScriptExecutor
/// </summary>
public class InboundScriptContext
{
public IReadOnlyDictionary<string, object?> Parameters { get; }
public ScriptParameters Parameters { get; }
public RouteHelper Route { get; }
public CancellationToken CancellationToken { get; }
@@ -161,7 +163,7 @@ public class InboundScriptContext
RouteHelper route,
CancellationToken cancellationToken = default)
{
Parameters = parameters;
Parameters = new ScriptParameters(parameters);
Route = route;
CancellationToken = cancellationToken;
}