diff --git a/src/MatBlazor.Demo/Demo/DemoMatTextField.razor b/src/MatBlazor.Demo/Demo/DemoMatTextField.razor index 36d31786..b40620d2 100644 --- a/src/MatBlazor.Demo/Demo/DemoMatTextField.razor +++ b/src/MatBlazor.Demo/Demo/DemoMatTextField.razor @@ -942,75 +942,119 @@

- string
+ string
Value: @stringValue

- sbyte
+ sbyte
Value: @sbyteValue

- byte
+ sbyte?
+ Value: @sbyteNullValue +

+

+ byte
Value: @byteValue

- short
+ byte?
+ Value: @byteNullValue +

+

+ short
Value: @shortValue

- ushort
+ short?
+ Value: @shortNullValue +

+

+ ushort
Value: @ushortValue

- int
+ ushort?
+ Value: @ushortNullValue +

+

+ int
Value: @intValue

- uint
+ int?
+ Value: @intNullValue +

+

+ uint
Value: @uintValue

- long
+ uint?
+ Value: @uintNullValue +

+

+ long
Value: @longValue

- ulong
+ long?
+ Value: @longNullValue +

+

+ ulong
Value: @ulongValue

- char
+ ulong?
+ Value: @ulongNullValue +

+

+ char
Value: @charValue

- float
+ char?
+ Value: @charNullValue +

+

+ float
Value: @floatValue

- double
+ float?
+ Value: @floatNullValue +

+

+ double
Value: @doubleValue

- decimal
+ double?
+ Value: @doubleNullValue +

+

+ decimal
Value: @decimalValue

- decimal?
+ decimal?
Value: @decimalNullValue

- DateTime
+ DateTime
Value: @dateTimeValue

- DateTime?
+ DateTime?
Value: @dateTimeNullValue

- bool
+ bool
Value: @boolValue

- bool?
+ bool?
Value: @boolNullValue

@@ -1018,16 +1062,27 @@ { string stringValue; sbyte sbyteValue; + sbyte? sbyteNullValue; byte byteValue; + byte? byteNullValue; short shortValue; + short? shortNullValue; ushort ushortValue; + ushort? ushortNullValue; int intValue; + int? intNullValue; uint uintValue; + uint? uintNullValue; long longValue; + long? longNullValue; ulong ulongValue; + ulong? ulongNullValue; char charValue; + char? charNullValue; float floatValue; + float? floatNullValue; double doubleValue; + double? doubleNullValue; decimal decimalValue; decimal? decimalNullValue; DateTime dateTimeValue; @@ -1048,46 +1103,90 @@ sbyte
Value: @sbyteValue

+

+ sbyte?
+ Value: @sbyteNullValue +

byte
Value: @byteValue

+

+ byte?
+ Value: @byteNullValue +

short
Value: @shortValue

+

+ short?
+ Value: @shortNullValue +

ushort
Value: @ushortValue

+

+ ushort?
+ Value: @ushortNullValue +

int
Value: @intValue

+

+ int?
+ Value: @intNullValue +

uint
Value: @uintValue

+

+ uint?
+ Value: @uintNullValue +

long
Value: @longValue

+

+ long?
+ Value: @longNullValue +

ulong
Value: @ulongValue

+

+ ulong?
+ Value: @ulongNullValue +

char
Value: @charValue

+

+ char?
+ Value: @charNullValue +

float
Value: @floatValue

+

+ float?
+ Value: @floatNullValue +

double
Value: @doubleValue

+

+ double?
+ Value: @doubleNullValue +

decimal
Value: @decimalValue @@ -1117,16 +1216,27 @@ { string stringValue; sbyte sbyteValue; + sbyte? sbyteNullValue; byte byteValue; + byte? byteNullValue; short shortValue; + short? shortNullValue; ushort ushortValue; + ushort? ushortNullValue; int intValue; + int? intNullValue; uint uintValue; + uint? uintNullValue; long longValue; + long? longNullValue; ulong ulongValue; + ulong? ulongNullValue; char charValue; + char? charNullValue; float floatValue; + float? floatNullValue; double doubleValue; + double? doubleNullValue; decimal decimalValue; decimal? decimalNullValue; DateTime dateTimeValue; diff --git a/src/MatBlazor.Demo/Demo/DemoNumericUpDownField.razor b/src/MatBlazor.Demo/Demo/DemoNumericUpDownField.razor index 8246a4e6..200c5f78 100644 --- a/src/MatBlazor.Demo/Demo/DemoNumericUpDownField.razor +++ b/src/MatBlazor.Demo/Demo/DemoNumericUpDownField.razor @@ -198,99 +198,151 @@

MatNumericUpDownField supports different generic types

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- +

- + + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+

- @code @@ -308,7 +360,17 @@ double v11; decimal v12; decimal? v13; - } + sbyte? v14; + byte? v15; + short? v16; + ushort? v17; + int? v18; + uint? v19; + long? v20; + ulong? v21; + char? v22; + float? v23; + double? v24; }
@@ -406,6 +468,72 @@

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

+

+ + +

@@ -424,6 +552,17 @@ double v11; decimal v12; decimal? v13; + sbyte? v14; + byte? v15; + short? v16; + ushort? v17; + int? v18; + uint? v19; + long? v20; + ulong? v21; + char? v22; + float? v23; + double? v24; } diff --git a/src/MatBlazor/Core/MatBlazorSwitchT.cs b/src/MatBlazor/Core/MatBlazorSwitchT.cs index 1c82d13f..735603ab 100644 --- a/src/MatBlazor/Core/MatBlazorSwitchT.cs +++ b/src/MatBlazor/Core/MatBlazorSwitchT.cs @@ -38,16 +38,27 @@ public virtual T FromBool(bool v) private static readonly MatSwitchT Ts = new MatSwitchT() .Case>(new MatBlazorSwitchTSByte()) + .Case>(new MatBlazorSwitchTSByteNull()) .Case>(new MatBlazorSwitchTByte()) + .Case>(new MatBlazorSwitchTByteNull()) .Case>(new MatBlazorSwitchTShort()) + .Case>(new MatBlazorSwitchTShortNull()) .Case>(new MatBlazorSwitchTUShort()) + .Case>(new MatBlazorSwitchTUShortNull()) .Case>(new MatBlazorSwitchTInt()) + .Case>(new MatBlazorSwitchTIntNull()) .Case>(new MatBlazorSwitchTUInt()) + .Case>(new MatBlazorSwitchTUIntNull()) .Case>(new MatBlazorSwitchTLong()) + .Case>(new MatBlazorSwitchTLongNull()) .Case>(new MatBlazorSwitchTULong()) + .Case>(new MatBlazorSwitchTULongNull()) .Case>(new MatBlazorSwitchTChar()) + .Case>(new MatBlazorSwitchTCharNull()) .Case>(new MatBlazorSwitchTFloat()) + .Case>(new MatBlazorSwitchTFloatNull()) .Case>(new MatBlazorSwitchTDouble()) + .Case>(new MatBlazorSwitchTDoubleNull()) .Case>(new MatBlazorSwitchTDecimal()) .Case>(new MatBlazorSwitchTDecimalNull()) .Case>(new MatBlazorSwitchTString()) diff --git a/src/MatBlazor/Core/MatBlazorSwitchTByteNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTByteNull.cs new file mode 100644 index 00000000..7c26dd69 --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTByteNull.cs @@ -0,0 +1,85 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTByteNull : MatBlazorSwitchT + { + public override byte? Increase(byte? v, byte? step, byte? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (byte?) ((v ?? 0) + (step ?? 0)) : null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override byte? Decrease(byte? v, byte? step, byte? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (byte?) ((v ?? 0) - (step ?? 0)) : null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override byte? Round(byte? v, int dp) + { + return v; + } + + public override byte? GetMinimum() => byte.MinValue; + public override byte? GetMaximum() => byte.MaxValue; + + public override byte? GetStep() => 1; + + public override string FormatValueAsString(byte? v, string format) + { + return v?.ToString(format); + } + + public override byte? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return byte.Parse(v, NumberStyles.Any); + } + + public override byte? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(byte? v) + { + throw new NotImplementedException(); + } + + public override byte? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override byte? FromDecimal(decimal v) + { + return (byte)v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTCharNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTCharNull.cs new file mode 100644 index 00000000..736fa406 --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTCharNull.cs @@ -0,0 +1,84 @@ +using System; + +namespace MatBlazor +{ + public class MatBlazorSwitchTCharNull : MatBlazorSwitchT + { + public override char? Increase(char? v, char? step, char? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (char?) ((v ?? 0) + (step ?? 0)) : null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override char? Decrease(char? v, char? step, char? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (char?) ((v ?? 0) - (step ?? 0)) : null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override char? Round(char? v, int dp) + { + return v; + } + + public override char? GetMinimum() => char.MinValue; + public override char? GetMaximum() => char.MaxValue; + + public override char? GetStep() => (char?)1; + + public override string FormatValueAsString(char? v, string format) + { + return v?.ToString(); + } + + public override char? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return char.Parse(v); + } + + public override char? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(char? v) + { + throw new NotImplementedException(); + } + + public override char? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override char? FromDecimal(decimal v) + { + return (char)v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTDoubleNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTDoubleNull.cs new file mode 100644 index 00000000..999b7b49 --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTDoubleNull.cs @@ -0,0 +1,90 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTDoubleNull : MatBlazorSwitchT + { + public override double? Increase(double? v, double? step, double? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (double?) null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override double? Decrease(double? v, double? step, double? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (double?) null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override double? Round(double? v, int dp) + { + if (v.HasValue) + { + return Math.Round(v.Value, dp); + } + + return v; + } + + public override double? GetMinimum() => double.MinValue; + public override double? GetMaximum() => double.MaxValue; + + public override double? GetStep() => 1; + + public override string FormatValueAsString(double? v, string format) + { + return v?.ToString(format); + } + + public override double? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return double.Parse(v, NumberStyles.Any); + } + + public override double? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(double? v) + { + throw new NotImplementedException(); + } + + public override double? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override double? FromDecimal(decimal v) + { + return (double) v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTFloatNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTFloatNull.cs new file mode 100644 index 00000000..53bc4c0a --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTFloatNull.cs @@ -0,0 +1,89 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTFloatNull : MatBlazorSwitchT + { + public override float? Increase(float? v, float? step, float? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (float?) null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override float? Decrease(float? v, float? step, float? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (float?) null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override float? Round(float? v, int dp) + { + if (v.HasValue) + { + return (float?)Math.Round(v.Value, dp); + } + + return v; + } + + public override float? GetMinimum() => float.MinValue; + public override float? GetMaximum() => float.MaxValue; + + public override float? GetStep() => 1; + + public override string FormatValueAsString(float? v, string format) + { + return v?.ToString(format); + } + public override float? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return float.Parse(v, NumberStyles.Any); + } + + public override float? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(float? v) + { + throw new NotImplementedException(); + } + + public override float? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override float? FromDecimal(decimal v) + { + return (float) v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTIntNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTIntNull.cs new file mode 100644 index 00000000..558025df --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTIntNull.cs @@ -0,0 +1,85 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTIntNull : MatBlazorSwitchT + { + public override int? Increase(int? v, int? step, int? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (int?) null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override int? Decrease(int? v, int? step, int? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (int?) null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override int? Round(int? v, int dp) + { + return v; + } + + public override int? GetMinimum() => int.MinValue; + public override int? GetMaximum() => int.MaxValue; + + public override int? GetStep() => 1; + + public override string FormatValueAsString(int? v, string format) + { + return v?.ToString(format); + } + + public override int? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return int.Parse(v, NumberStyles.Any); + } + + public override int? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(int? v) + { + throw new NotImplementedException(); + } + + public override int? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override int? FromDecimal(decimal v) + { + return (int) v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTLongNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTLongNull.cs new file mode 100644 index 00000000..bf8dacfd --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTLongNull.cs @@ -0,0 +1,85 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTLongNull : MatBlazorSwitchT + { + public override long? Increase(long? v, long? step, long? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (long?) null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override long? Decrease(long? v, long? step, long? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (long?) null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override long? Round(long? v, int dp) + { + return v; + } + + public override long? GetMinimum() => long.MinValue; + public override long? GetMaximum() => long.MaxValue; + + public override long? GetStep() => 1; + + public override string FormatValueAsString(long? v, string format) + { + return v?.ToString(format); + } + + public override long? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return long.Parse(v, NumberStyles.Any); + } + + public override long? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(long? v) + { + throw new NotImplementedException(); + } + + public override long? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override long? FromDecimal(decimal v) + { + return (long) v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTSByteNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTSByteNull.cs new file mode 100644 index 00000000..474de964 --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTSByteNull.cs @@ -0,0 +1,85 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTSByteNull : MatBlazorSwitchT + { + public override sbyte? Increase(sbyte? v, sbyte? step, sbyte? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (sbyte?) ((v ?? 0) + (step ?? 0)) : null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override sbyte? Decrease(sbyte? v, sbyte? step, sbyte? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (sbyte?) ((v ?? 0) - (step ?? 0)) : null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override sbyte? Round(sbyte? v, int dp) + { + return v; + } + + public override sbyte? GetMinimum() => sbyte.MinValue; + public override sbyte? GetMaximum() => sbyte.MaxValue; + + public override sbyte? GetStep() => 1; + + public override string FormatValueAsString(sbyte? v, string format) + { + return v?.ToString(format); + } + + public override sbyte? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return sbyte.Parse(v, NumberStyles.Any); + } + + public override sbyte? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(sbyte? v) + { + throw new NotImplementedException(); + } + + public override sbyte? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override sbyte? FromDecimal(decimal v) + { + return (sbyte) v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTShortNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTShortNull.cs new file mode 100644 index 00000000..d74d5ae2 --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTShortNull.cs @@ -0,0 +1,85 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTShortNull : MatBlazorSwitchT + { + public override short? Increase(short? v, short? step, short? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (short?) ((v ?? 0) + (step ?? 0)) : null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override short? Decrease(short? v, short? step, short? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (short?) ((v ?? 0) - (step ?? 0)) : null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override short? Round(short? v, int dp) + { + return v; + } + + public override short? GetMinimum() => short.MinValue; + public override short? GetMaximum() => short.MaxValue; + + public override short? GetStep() => 1; + + public override string FormatValueAsString(short? v, string format) + { + return v?.ToString(format); + } + + public override short? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return short.Parse(v, NumberStyles.Any); + } + + public override short? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(short? v) + { + throw new NotImplementedException(); + } + + public override short? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override short? FromDecimal(decimal v) + { + return (short) v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTUIntNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTUIntNull.cs new file mode 100644 index 00000000..8bd9ed1b --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTUIntNull.cs @@ -0,0 +1,85 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTUIntNull : MatBlazorSwitchT + { + public override uint? Increase(uint? v, uint? step, uint? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (uint?) null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override uint? Decrease(uint? v, uint? step, uint? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (uint?) null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override uint? Round(uint? v, int dp) + { + return v; + } + + public override uint? GetMinimum() => uint.MinValue; + public override uint? GetMaximum() => uint.MaxValue; + + public override uint? GetStep() => 1; + + public override string FormatValueAsString(uint? v, string format) + { + return v?.ToString(format); + } + + public override uint? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return uint.Parse(v, NumberStyles.Any); + } + + public override uint? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(uint? v) + { + throw new NotImplementedException(); + } + + public override uint? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override uint? FromDecimal(decimal v) + { + return (uint) v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTULongNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTULongNull.cs new file mode 100644 index 00000000..55dd33d2 --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTULongNull.cs @@ -0,0 +1,85 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTULongNull : MatBlazorSwitchT + { + public override ulong? Increase(ulong? v, ulong? step, ulong? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) + (step ?? 0)) : (ulong?) null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override ulong? Decrease(ulong? v, ulong? step, ulong? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? ((v ?? 0) - (step ?? 0)) : (ulong?) null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override ulong? Round(ulong? v, int dp) + { + return v; + } + + public override ulong? GetMinimum() => ulong.MinValue; + public override ulong? GetMaximum() => ulong.MaxValue; + + public override ulong? GetStep() => 1; + + public override string FormatValueAsString(ulong? v, string format) + { + return v?.ToString(format); + } + + public override ulong? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return ulong.Parse(v, NumberStyles.Any); + } + + public override ulong? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(ulong? v) + { + throw new NotImplementedException(); + } + + public override ulong? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override ulong? FromDecimal(decimal v) + { + return (ulong) v; + } + } +} \ No newline at end of file diff --git a/src/MatBlazor/Core/MatBlazorSwitchTUShortNull.cs b/src/MatBlazor/Core/MatBlazorSwitchTUShortNull.cs new file mode 100644 index 00000000..6178d165 --- /dev/null +++ b/src/MatBlazor/Core/MatBlazorSwitchTUShortNull.cs @@ -0,0 +1,85 @@ +using System; +using System.Globalization; + +namespace MatBlazor +{ + public class MatBlazorSwitchTUShortNull : MatBlazorSwitchT + { + public override ushort? Increase(ushort? v, ushort? step, ushort? max) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (ushort?) ((v ?? 0) + (step ?? 0)) : null; + return (max.HasValue && v2.HasValue) ? (v2.Value <= max.Value ? v2.Value : max.Value) : v2; + } + catch (OverflowException e) + { + return max; + } + } + } + + public override ushort? Decrease(ushort? v, ushort? step, ushort? min) + { + checked + { + try + { + var v2 = (v.HasValue || step.HasValue) ? (ushort?) ((v ?? 0) - (step ?? 0)) : null; + return (min.HasValue && v2.HasValue) ? (v2.Value >= min.Value ? v2.Value : min.Value) : v2; + } + catch (OverflowException e) + { + return min; + } + } + } + + public override ushort? Round(ushort? v, int dp) + { + return v; + } + + public override ushort? GetMinimum() => ushort.MinValue; + public override ushort? GetMaximum() => ushort.MaxValue; + + public override ushort? GetStep() => 1; + + public override string FormatValueAsString(ushort? v, string format) + { + return v?.ToString(format); + } + + public override ushort? ParseFromString(string v, string format) + { + if (string.IsNullOrEmpty(v)) + { + return null; + } + + return ushort.Parse(v, NumberStyles.Any); + } + + public override ushort? FromDateTimeNull(DateTime? v) + { + throw new NotImplementedException(); + } + + public override DateTime? ToDateTimeNull(ushort? v) + { + throw new NotImplementedException(); + } + + public override ushort? FromBoolNull(bool? v, bool indeterminate) + { + throw new NotImplementedException(); + } + + public override ushort? FromDecimal(decimal v) + { + return (ushort) v; + } + } +} \ No newline at end of file