Using the .NET Core Microsoft.Extensions.Configuration
is it possible to bind to a Configuration to an object that contains an array?
ConfigurationBinder
has a method BindArray, so I'd assume it would work.
But when I try it out I get an exception:
System.NotSupportedException: ArrayConverter cannot convert from System.String.
Here's my slimmed down code:
public class Test
{
private class ExampleOption
{
public int[] Array {get;set;}
}
[Test]
public void CanBindArray()
{
// ARRANGE
var config =
new ConfigurationBuilder()
.AddInMemoryCollection(new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("Array", "[1,2,3]")
})
.Build();
var exampleOption= new ExampleOption();
// ACT
config.Bind(complexOptions); // throws exception
// ASSERT
exampleOption.ShouldContain(1);
}
}