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

DictionaryConverter

using Castle.Core.Configuration; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; namespace Castle.MicroKernel.SubSystems.Conversion { [Serializable] public class DictionaryConverter : AbstractTypeConverter { public override bool CanHandleType(Type type) { if (!(type == typeof(IDictionary))) return type == typeof(Hashtable); return true; } public override object PerformConversion(string value, Type targetType) { throw new NotImplementedException(); } public override object PerformConversion(IConfiguration configuration, Type targetType) { Dictionary<object, object> dictionary = new Dictionary<object, object>(); string text = ((NameValueCollection)configuration.get_Attributes())["keyType"]; Type type = typeof(string); string text2 = ((NameValueCollection)configuration.get_Attributes())["valueType"]; Type type2 = typeof(string); if (text != null) type = base.Context.Composition.PerformConversion<Type>(text); if (text2 != null) type2 = base.Context.Composition.PerformConversion<Type>(text2); foreach (IConfiguration item in (List<IConfiguration>)configuration.get_Children()) { string text3 = ((NameValueCollection)item.get_Attributes())["key"]; if (text3 == null) throw new ConverterException("You must provide a key for the dictionary entry"); Type targetType2 = type; if (((NameValueCollection)item.get_Attributes())["keyType"] != null) targetType2 = base.Context.Composition.PerformConversion<Type>(((NameValueCollection)item.get_Attributes())["keyType"]); object key = base.Context.Composition.PerformConversion(text3, targetType2); Type targetType3 = type2; if (((NameValueCollection)item.get_Attributes())["valueType"] != null) targetType3 = base.Context.Composition.PerformConversion<Type>(((NameValueCollection)item.get_Attributes())["valueType"]); object value = (((List<IConfiguration>)item.get_Children()).Count != 0) ? base.Context.Composition.PerformConversion(((List<IConfiguration>)item.get_Children())[0], targetType3) : base.Context.Composition.PerformConversion(item, targetType3); dictionary.Add(key, value); } return dictionary; } } }