Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/Core/Components/Base/InputHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ namespace Microsoft.FluentUI.AspNetCore.Components;

internal static class InputHelpers<TValue>
{

public static string GetMaxValue()
{
Type? targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue);
Expand Down Expand Up @@ -51,17 +50,27 @@ public static string GetMinValue()
return value;
}

internal static void ValidateIntegerInputs(string? max, string? min)

internal static void ValidateSByteInputs(string max, string min)
{
var maxValue = Convert.ToSByte(max, CultureInfo.InvariantCulture);
var minValue = Convert.ToSByte(min, CultureInfo.InvariantCulture);

if (maxValue < minValue)
{
throw new ArgumentException("Float Max value is smaller than Min value.");
}
}

internal static void ValidateIntegerInputs(string? max, string? min)
{
var maxValue = Convert.ToInt32(max);
var minValue = Convert.ToInt32(min);

if (maxValue < minValue)
{
throw new ArgumentException("Integer Max value is smaller then Min value.");
}

}

internal static void ValidateLongInputs(string? max, string? min)
Expand Down Expand Up @@ -137,6 +146,11 @@ internal static void ValidateInputParameters(string? max, string? min)
return; //nothing to validate
}

if (typeof(TValue) == typeof(sbyte))
{
ValidateSByteInputs(max, min);
}

if (typeof(TValue) == typeof(int))
{
ValidateIntegerInputs(max, min);
Expand All @@ -149,7 +163,6 @@ internal static void ValidateInputParameters(string? max, string? min)

if (typeof(TValue) == typeof(short))
{

ValidateShortInputs(max, min);
}

Expand All @@ -165,7 +178,6 @@ internal static void ValidateInputParameters(string? max, string? min)

if (typeof(TValue) == typeof(decimal))
{

ValidateDecimalInputs(max, min);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ private static string GetStepAttributeValue()
// Unwrap Nullable<T>, because InputBase already deals with the Nullable aspect
// of it for us. We will only get asked to parse the T for nonempty inputs.
var targetType = Nullable.GetUnderlyingType(typeof(TValue)) ?? typeof(TValue);
if (targetType == typeof(int) ||
if (targetType == typeof(sbyte) ||
targetType == typeof(int) ||
targetType == typeof(long) ||
targetType == typeof(short) ||
targetType == typeof(float) ||
Expand Down Expand Up @@ -119,6 +120,7 @@ protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(fa
return value switch
{
null => null,
sbyte @sbyte => BindConverter.FormatValue(Convert.ToInt16(@sbyte), CultureInfo.InvariantCulture),
int @int => BindConverter.FormatValue(@int, CultureInfo.InvariantCulture),
long @long => BindConverter.FormatValue(@long, CultureInfo.InvariantCulture),
short @short => BindConverter.FormatValue(@short, CultureInfo.InvariantCulture),
Expand Down