Skip to content

Commit cc156c6

Browse files
tomasfilTomáš Filip
andauthored
[FIX] nullable conversions (#3316)
* Fix nullable conversions * Fix when passing null, instead of string.Empty * Fix compiler error Co-authored-by: Tomáš Filip <[email protected]>
1 parent f6aa117 commit cc156c6

7 files changed

+84
-0
lines changed

src/ReactiveUI/Bindings/Converter/NullableByteToStringTypeConverter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
4444
return true;
4545
}
4646

47+
if (from is null)
48+
{
49+
result = null!;
50+
return true;
51+
}
52+
4753
if (from is string fromString)
4854
{
55+
if (string.IsNullOrEmpty(fromString))
56+
{
57+
result = null!;
58+
return true;
59+
}
60+
4961
var success = byte.TryParse(fromString, out var outByte);
5062
if (success)
5163
{

src/ReactiveUI/Bindings/Converter/NullableDecimalToStringTypeConverter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
4444
return true;
4545
}
4646

47+
if (from is null)
48+
{
49+
result = null!;
50+
return true;
51+
}
52+
4753
if (from is string fromString)
4854
{
55+
if (string.IsNullOrEmpty(fromString))
56+
{
57+
result = null!;
58+
return true;
59+
}
60+
4961
var success = decimal.TryParse(fromString, out var outDecimal);
5062
if (success)
5163
{

src/ReactiveUI/Bindings/Converter/NullableDoubleToStringTypeConverter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
4444
return true;
4545
}
4646

47+
if (from is null)
48+
{
49+
result = null!;
50+
return true;
51+
}
52+
4753
if (from is string fromString)
4854
{
55+
if (string.IsNullOrEmpty(fromString))
56+
{
57+
result = null!;
58+
return true;
59+
}
60+
4961
var success = double.TryParse(fromString, out var outDouble);
5062
if (success)
5163
{

src/ReactiveUI/Bindings/Converter/NullableIntegerToStringTypeConverter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
4444
return true;
4545
}
4646

47+
if (from is null)
48+
{
49+
result = null!;
50+
return true;
51+
}
52+
4753
if (from is string fromString)
4854
{
55+
if (string.IsNullOrEmpty(fromString))
56+
{
57+
result = null!;
58+
return true;
59+
}
60+
4961
var success = int.TryParse(fromString, out var outInt);
5062
if (success)
5163
{

src/ReactiveUI/Bindings/Converter/NullableLongToStringTypeConverter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
4444
return true;
4545
}
4646

47+
if (from is null)
48+
{
49+
result = null!;
50+
return true;
51+
}
52+
4753
if (from is string fromString)
4854
{
55+
if (string.IsNullOrEmpty(fromString))
56+
{
57+
result = null!;
58+
return true;
59+
}
60+
4961
var success = long.TryParse(fromString, out var outLong);
5062
if (success)
5163
{

src/ReactiveUI/Bindings/Converter/NullableShortToStringTypeConverter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
4444
return true;
4545
}
4646

47+
if (from is null)
48+
{
49+
result = null!;
50+
return true;
51+
}
52+
4753
if (from is string fromString)
4854
{
55+
if (string.IsNullOrEmpty(fromString))
56+
{
57+
result = null!;
58+
return true;
59+
}
60+
4961
var success = short.TryParse(fromString, out var outShort);
5062
if (success)
5163
{

src/ReactiveUI/Bindings/Converter/NullableSingleToStringTypeConverter.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
4444
return true;
4545
}
4646

47+
if (from is null)
48+
{
49+
result = null!;
50+
return true;
51+
}
52+
4753
if (from is string fromString)
4854
{
55+
if (string.IsNullOrEmpty(fromString))
56+
{
57+
result = null!;
58+
return true;
59+
}
60+
4961
var success = float.TryParse(fromString, out var outSingle);
5062
if (success)
5163
{

0 commit comments

Comments
 (0)