dotnet/runtime

Support TypeConverterAttribute on bound properties

Open

#36,545 建立於 2017年3月18日

在 GitHub 查看
 (10 留言) (17 反應) (0 負責人)C# (5,445 fork)batch import
area-Extensions-Configurationfeature-requesthelp wanted

倉庫指標

Star
 (17,886 star)
PR 合併指標
 (平均合併 12天 11小時) (30 天內合併 661 個 PR)

描述

It's very difficult to add a custom TypeConverter for framework types to have them bind correctly within ConfigurationBinder. The documentation for TypeConverterAttribute specifies that the attribute can be attached to a property, and that property will then use the specified TypeConverter during serialization/deserialization. Unfortunately, ConfigurationBinder doesn't take the property's attributes into consideration during BindProperty, instead passing the binding off to BindInstance with just the type of the property.

Presently, the only way to use custom TypeConverters is to register them using TypeDescriptor.AddAttributes before any configuration binding occurs, which is inconvenient if your library requires custom TypeConverters for standard types.

貢獻者指南