Fix/issue 441#471
Conversation
|
Hi everyone! |
nblumhardt
left a comment
There was a problem hiding this comment.
Thanks for sending this!
params is now supported on spans, enumerables, and other collections:
It would be great to extend test coverage to make sure these cases work, or at least degrade gracefully.
| $"This is not supported when only a `IConfigSection` has been provided. (method '{methodToInvoke}')"); | ||
| } | ||
|
|
||
| if (parameter.IsDefined(typeof(ParamArrayAttribute), false)) |
There was a problem hiding this comment.
If this is modified to:
if (parameter.IsDefined(typeof(ParamArrayAttribute), false) &&
parameter.ParameterType.GetElementType() is {} elementType)
then elementType can be used in the CreateInstance call without !, and we'll also not fail in (as yet unknown) cases where ParamArrayAttribute is present but the parameter type isn't an array.
There was a problem hiding this comment.
I’ve updated the PR!
This new params support begs the question, should this library handle these cases, and if so how?
Ideas:
- IEnumerable could just return an array, closest type to it, and further handling can happen on the client side
- List and other generics I think can be handled generically, by returning an instance of the collection with T type
- ReadOnlySpan is a whole different beast.. and could be a big change since now we are returning
object?inGetImplicitValueForNotSpecifiedKeyso this method won't be able to handle it.
|
LGTM, thanks. It would be nice to extend support to different |
Fixes #441
Problem
When a configuration method has a params array parameter (e.g. params string[] ids) and the Args section is omitted entirely from config, the library fails to invoke the method at startup with:
System.ArgumentException: Object of type 'System.DBNull' cannot be converted to type 'System.String[]'.
This happens because:
Changes
ConfigurationReader.cs
internal to allow direct unit testing
ConfigurationReaderTests.cs
Root cause
In .NET 10, params parameters report HasDefaultValue = true but DefaultValue is DBNull — not a valid value for an array type. The fix intercepts params parameters before falling through to return parameter.DefaultValue.