Skip to content

Commit

Permalink
[FIX] nullable conversions (#3316)
Browse files Browse the repository at this point in the history
* Fix nullable conversions

* Fix when passing null, instead of string.Empty

* Fix compiler error

Co-authored-by: Tomáš Filip <[email protected]>
  • Loading branch information
tomasfil and Tomáš Filip authored Jul 19, 2022
1 parent f6aa117 commit cc156c6
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
return true;
}

if (from is null)
{
result = null!;
return true;
}

if (from is string fromString)
{
if (string.IsNullOrEmpty(fromString))
{
result = null!;
return true;
}

var success = byte.TryParse(fromString, out var outByte);
if (success)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
return true;
}

if (from is null)
{
result = null!;
return true;
}

if (from is string fromString)
{
if (string.IsNullOrEmpty(fromString))
{
result = null!;
return true;
}

var success = decimal.TryParse(fromString, out var outDecimal);
if (success)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
return true;
}

if (from is null)
{
result = null!;
return true;
}

if (from is string fromString)
{
if (string.IsNullOrEmpty(fromString))
{
result = null!;
return true;
}

var success = double.TryParse(fromString, out var outDouble);
if (success)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
return true;
}

if (from is null)
{
result = null!;
return true;
}

if (from is string fromString)
{
if (string.IsNullOrEmpty(fromString))
{
result = null!;
return true;
}

var success = int.TryParse(fromString, out var outInt);
if (success)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
return true;
}

if (from is null)
{
result = null!;
return true;
}

if (from is string fromString)
{
if (string.IsNullOrEmpty(fromString))
{
result = null!;
return true;
}

var success = long.TryParse(fromString, out var outLong);
if (success)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
return true;
}

if (from is null)
{
result = null!;
return true;
}

if (from is string fromString)
{
if (string.IsNullOrEmpty(fromString))
{
result = null!;
return true;
}

var success = short.TryParse(fromString, out var outShort);
if (success)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,20 @@ public bool TryConvert(object? from, Type toType, object? conversionHint, out ob
return true;
}

if (from is null)
{
result = null!;
return true;
}

if (from is string fromString)
{
if (string.IsNullOrEmpty(fromString))
{
result = null!;
return true;
}

var success = float.TryParse(fromString, out var outSingle);
if (success)
{
Expand Down

0 comments on commit cc156c6

Please sign in to comment.