using Microsoft.Extensions.Configuration;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Globalization;
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>()
var options = configuration.Get<Options>();
Console.WriteLine("Binding success.");
Console.WriteLine("Binding failure.");
[TypeConverter(typeof(ItemCollectionConverter))]
public ItemCollection Items { get; set; }
[TypeConverter(typeof(ItemCollectionConverter))]
class ItemCollection : ReadOnlyCollection<string>
public ItemCollection(IList<string> list) : base(list)
class ItemCollectionConverter : TypeConverter
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
return sourceType == typeof(IConfigurationSection);
public override object ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
var items = new List<string>();
foreach (var childSection in ((IConfigurationSection) value).GetChildren())
items.Add(childSection.Value!);
return new ItemCollection(items);