VB -> C#: Problem converting long if statement with nullable integers
See original GitHub issueVB.Net input code
'Dim newDays As Integer?
'Dim oldDays As Integer?
If (newDays.HasValue AndAlso Not oldDays.HasValue) _
OrElse (newDays.HasValue AndAlso oldDays.HasValue AndAlso newDays <> oldDays) _
OrElse (Not newDays.HasValue AndAlso oldDays.HasValue) Then
'Some code
End If
Erroneous output
if ((bool)((newDays.HasValue && !oldDays.HasValue ? true : newDays.HasValue && oldDays.HasValue ? newDays is var arg1 && oldDays is { } arg2 && arg1.HasValue ? arg1 != arg2 : null : false).GetValueOrDefault() || !newDays.HasValue && oldDays.HasValue))
// Some code
Expected output
if ((newDays.HasValue && !oldDays.HasValue) || (newDays.HasValue && oldDays.HasValue && newDays != oldDays) || (!newDays.HasValue && oldDays.HasValue))
Details
- Product in use: e.g. both
- Version in use: e.g. 9.1.2
- Did you see it working in a previous version, which? No
- Any other relevant information to the issue, or your interest in contributing a fix.
Issue Analytics
- State:
- Created 8 months ago
- Comments:12 (9 by maintainers)
Top Results From Across the Web
c# - if condition with nullable
It's because a nullable bool cannot be implicitly converted to a bool. It's the same reason why you can do this : int...
Read more >c# - Convert a boxed integer to an nullable ...
The ChangeType(Object, Type) method can convert a nullable type to another type. However, it cannot convert another type to a value of a ......
Read more >Resolve nullable warnings
Several compiler warnings indicate code that isn't null-safe. Learn how to address those warnings by making your code more resilient.
Read more >Null-conditional Operators - Visual Basic
The null-conditional operators are short-circuiting. If one operation in a chain of conditional member access and index operations returns ...
Read more >Solved: Expression.Error: We cannot convert the value null...
Everything were fine until yesterday when I started to get error Expression.Error: We cannot convert the value null to type Number from several...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should be available now. I know some cases will still be ugly so if you see other nullable related issues in the new version, feel free to reopen this with as many examples as you can find. Thanks!
Thanks for the thoughts on this. After putting together #984 I have even more appreciation for your previous work on it (and the tests that went with it) so thanks again for that too. I made a start on points 1 and 3, and believe I have dealt with the
Conversions.ToInteger
issue. That’s about all the time I have to work on this for now, so feel free to pick up where I left off if you’re interested. I’ll close this issue since I believe I’ve covered the examples given, but just reopen it or create a new issue if there are more examples worth fixing