Open PunzunLtd opened 1 month ago
We are focused mostly on the native and primitive types, as that is what most users use. We might implement extra logic to cover some extra types, like in your example. But at the moment, we are limited in resources with some more urgent features.
That being said. We are open to contributions. For this, you might be perfect as you are most knowledgeable on what needs to be covered.
OK. When I get a minute, I'll send in a PR. I see that you've got a release scheduled for July 15th, so I'll make sure to get it in before then.
I have a custom
Money
class that I wanted to use with theNumericEdit
control. I wound up having to subclass the control becauseNumericEdit
has a hard-coded list of types that it recognizes in theFormatValueAsString(TValue)
method.Our
Money
class has an implicit conversion toSystem.Decimal
and implements most of theSystem.Numerics
interfaces.Proposed solution In
Blazorise.Utilities.Converters
, replaceFormatValue(byte, CultureInfo)
and similar methods that simply callvalue?.ToString
with a single method:public static string FormatValue( ISpanFormattable? value, CultureInfo? culture = null) => value?.ToString( culture ?? CultureInfo.CurrentCulture)
Also, add to
TryChangeType<TValue>
before the finalelse
condition:else if (typeof(TValue).GetInterfaces().Contains(typeof(IParsable<TValue>))) result = (TValue)Convert.ChangeType((result as IParsable<TValue>).Parse(value.ToString()), conversionType, cultureInfo ?? CultureInfo.InvariantCulture)
In
Blazorise.NumericEdit:FormatValueString
, add a switch condition at the end (so that concrete conversions are tried first):ISpanFormattable formattable => Converters.FormatValue( formattable, CurrentCultureInfo ),
Additional context
Program to interfaces, not to implementations.