chore: Add position index to IDataStreamFactory input args
This commit is contained in:
1 parent
12fadab839
commit
bc39b8fda9
2 files changed
+12
-5
No files matched your search
@@ -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;
|
||||
|
||||
@@ -47,7 +47,17 @@ class StreamFactoryArgStore {
|
||||
names = names.SelectMany(n => n.Split(','));
|
||||
}
|
||||
IEnumerable<string> regexNames = att?.RegexNames ?? Enumerable.Empty<string>();
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user