feat: Add pseudo member (extension) function calls to DSL

This commit is contained in:
John Colvin committed 2025-11-15 12:45:07 -05:00
1 parent 4a2a814af0
commit 6045c602dc
5 files changed
+111 -34

No files matched your search

@@ -0,0 +1,35 @@
#nullable enable
namespace Bts.DataStreamCore;
using System;
using System.Collections.Generic;
using System.Linq;
public class CompositeExtensionFunctionEvaluator : IExtensionFunctionEvaluator {
readonly List<IExtensionFunctionEvaluator> evaluators = new();
public CompositeExtensionFunctionEvaluator(Type targetType) {
TargetType = targetType;
}
public Type TargetType { get; }
public IEnumerable<string> SupportedFunctions => evaluators.SelectMany(e => e.SupportedFunctions);
public void Add(IExtensionFunctionEvaluator evaluator) {
if (evaluator.TargetType != TargetType) {
throw new ArgumentException("TargetType does not match composite evaluator's TargetType", nameof(evaluator));
}
evaluators.Add(evaluator);
}
public object? Evaluate(string functionId, object target, IEnumerable<(string? Name, int? Index, object? Value)> args) {
var targetType = target.GetType();
foreach (var eval in evaluators) {
if (eval.SupportedFunctions.Contains(functionId) && targetType.IsAssignableTo(eval.TargetType)) {
return eval.Evaluate(functionId, target, args);
}
}
return null;
}
}