dotnet/runtime

Support TypeConverterAttribute on bound properties

オープン

#36,545 opened on 2017/03/18

 (10 件のコメント) (17 件のリアクション) (0 人の担当者)C# (5,445 件のフォーク)batch import
area-Extensions-Configurationfeature-requesthelp wanted

Repository metrics

Stars
 (17,886 個のスター)
PR merge metrics
 (平均マージ 12d 11h) (30d で 661 merged PRs)

説明

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.

コントリビューターガイド