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

EnumConverter

Converts a string representation to an enum value
using Castle.Core.Configuration; using System; using System.Reflection; namespace Castle.MicroKernel.SubSystems.Conversion { [Serializable] public class EnumConverter : AbstractTypeConverter { public override bool CanHandleType(Type type) { return type.GetTypeInfo().IsEnum; } public override object PerformConversion(string value, Type targetType) { try { return Enum.Parse(targetType, value, true); } catch (ConverterException) { throw; } catch (Exception innerException) { throw new ConverterException($"""{value}""{targetType.FullName}""", innerException); } } public override object PerformConversion(IConfiguration configuration, Type targetType) { return PerformConversion(configuration.get_Value(), targetType); } } }