You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a custom Money class that I wanted to use with the NumericEdit control. I wound up having to subclass the control because NumericEdit has a hard-coded list of types that it recognizes in the FormatValueAsString(TValue) method.
Our Money class has an implicit conversion to System.Decimal and implements most of the System.Numerics interfaces.
Proposed solution
In Blazorise.Utilities.Converters, replace FormatValue(byte, CultureInfo) and similar methods that simply call value?.ToString with a single method:
Also, add to TryChangeType<TValue> before the final else 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):
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.
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.
The text was updated successfully, but these errors were encountered: