-
Notifications
You must be signed in to change notification settings - Fork 400
Description
Is your feature request related to a problem? Please describe.
The QuantityTypeConverter<TQuantity>
class included with UnitsNet provides a type converter that can be used, for example for Length
, by applying the attribute [TypeConverter(typeof(QuantityTypeConverter<Length>))]
to each property that requires type conversion. However, this can be a lot of properties and is easy to forget to do.
Describe the solution you'd like
Typically, when a class is distributed with a type converter, it is associated with the declaration of the class so that the type converter will be picked up by default whenever one is needed. The type converter can still be overridden by applying a type converter attribute to the property. Following the usual convention, I think all quantity types should have a type converter applied to their class using the TypeConverterAttribute
.
Describe alternatives you've considered
Users of the UnitsNet library can work around this using one of two techniques:
- Apply a
TypeConverter
attribute to each property that requires type conversion. - Registering a default type converter using
TypeDescriptor.AddAttributes(typeof(TQuantity), new TypeConverterAttribute(typeof(QuantityTypeConverter<TQuantity>)));
. Note that this must be done very early in the application to ensure the registration is done before the type converter is requested usingTypeDescriptor.GetConverter(typeof(TQuantity))
.