<PackageReference Include="Castle.Windsor" Version="3.2.1" />

GenericListConverter

using Castle.Core.Configuration; using Castle.Core.Internal; using System; using System.Collections.Generic; using System.Collections.Specialized; namespace Castle.MicroKernel.SubSystems.Conversion { [Serializable] public class GenericListConverter : AbstractTypeConverter { private class ListHelper<T> : IGenericCollectionConverterHelper { private readonly GenericListConverter parent; public ListHelper(GenericListConverter parent) { this.parent = parent; } public object ConvertConfigurationToCollection(IConfiguration configuration) { List<T> list = new List<T>(); foreach (IConfiguration item2 in (List<IConfiguration>)configuration.get_Children()) { T item = parent.Context.Composition.PerformConversion<T>(item2); list.Add(item); } return list; } } public override bool CanHandleType(Type type) { if (!type.IsGenericType) return false; Type genericTypeDefinition = type.GetGenericTypeDefinition(); if (!(genericTypeDefinition == typeof(IList<>)) && !(genericTypeDefinition == typeof(ICollection<>)) && !(genericTypeDefinition == typeof(List<>))) return genericTypeDefinition == typeof(IEnumerable<>); return true; } public override object PerformConversion(string value, Type targetType) { throw new NotImplementedException(); } public override object PerformConversion(IConfiguration configuration, Type targetType) { Type[] genericArguments = targetType.GetGenericArguments(); if (genericArguments.Length != 1) throw new ConverterException("Expected type with one generic argument."); string text = ((NameValueCollection)configuration.get_Attributes())["type"]; Type type = genericArguments[0]; if (text != null) type = base.Context.Composition.PerformConversion<Type>(text); Type subtypeofTBase = typeof(ListHelper<>).MakeGenericType(type); IGenericCollectionConverterHelper genericCollectionConverterHelper = subtypeofTBase.CreateInstance<IGenericCollectionConverterHelper>(new object[1] { this }); return genericCollectionConverterHelper.ConvertConfigurationToCollection(configuration); } } }