Skip to content

Breaking changes on ConfigurationBinder behaviour #58330

@mapogolions

Description

@mapogolions

Description

Before this changes I could convert any non-terminal section (section that doesn't have a value, but has child keys) to an array as shown the example below. This is not possible in the current implementation.

var configRoot = new ConfigurationBuilder()
    .AddInMemoryCollection(new KeyValuePair<string, string>[]
    {
        new("section:key1", "1"),
        new("section:key2", "2"),
        new("section:key3", "3")
        /**
         {
             "section": {
                 "key1": "1",
                 "key2": "2",
                 "key3": "3"
             }
         }
        */
    })
    .Build();
var values = configRoot.GetSection("section").Get<int[]>();


Assert.Equal(3, values.Length);
Assert.Equal(1, values[0]);
Assert.Equal(2, values[1]);
Assert.Equal(3, values[2]);

Other information

This line of code requires the child key (as "key1", "key2", "key3" in example above) to be an integer.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions