From bc39b8fda970110b7269bfb68e06aff1786cabb1 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Thu, 21 Aug 2025 00:29:49 -0400 Subject: [PATCH] chore: Add position index to IDataStreamFactory input args --- .../StreamFactories/StreamArgumentAttribute.cs | 1 + .../StreamFactories/StreamFactoryArgStore.cs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/DataStreamSuite/SharedStreams/StreamFactories/StreamArgumentAttribute.cs b/src/DataStreamSuite/SharedStreams/StreamFactories/StreamArgumentAttribute.cs index c2a476036..5c74215fa 100644 --- a/src/DataStreamSuite/SharedStreams/StreamFactories/StreamArgumentAttribute.cs +++ b/src/DataStreamSuite/SharedStreams/StreamFactories/StreamArgumentAttribute.cs @@ -14,6 +14,7 @@ public class StreamArgumentAttribute : Attribute { public string[] Names { get; } public string[] RegexNames { get; set; } + public int Position { get; set; } = -1; public WellKnownStreamArgumentType WellKnownType { get; } public bool IsRequired { get; set; } public bool AllowCommaSeparatedAliases { get; set; } = true; diff --git a/src/DataStreamSuite/SharedStreams/StreamFactories/StreamFactoryArgStore.cs b/src/DataStreamSuite/SharedStreams/StreamFactories/StreamFactoryArgStore.cs index f262c3dc8..4d54a77dc 100644 --- a/src/DataStreamSuite/SharedStreams/StreamFactories/StreamFactoryArgStore.cs +++ b/src/DataStreamSuite/SharedStreams/StreamFactories/StreamFactoryArgStore.cs @@ -47,7 +47,17 @@ class StreamFactoryArgStore { names = names.SelectMany(n => n.Split(',')); } IEnumerable regexNames = att?.RegexNames ?? Enumerable.Empty(); - if (TryGet(names, out var val) || TryGetRegex(regexNames, out val) ) { + if (TryGet(names, out var val) || TryGetRegex(regexNames, out val)) { + SetValue(val); + } else if (att is not null && att.Position >= 0 && args.Skip(att.Position).TryGetFirst(out var arg)) { + SetValue(arg.Value); + } else if (att?.IsRequired ?? false) { + errorMessage = $"Missing required param '{p.Name}'"; + result = default; + return false; + } + + void SetValue(object? val) { var pType = p.PropertyType; bool isNullable = pType.IsNullable(); if (isNullable) { @@ -74,10 +84,6 @@ class StreamFactoryArgStore { p.SetValue(res, pVal.assert_value()); } } - } else if (att?.IsRequired ?? false) { - errorMessage = $"Missing required param '{p.Name}'"; - result = default; - return false; } } errorMessage = null;