-
Notifications
You must be signed in to change notification settings - Fork 5k
Simplify conditional operator #112074
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify conditional operator #112074
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -314,12 +314,12 @@ internal static object DefaultToType(IConvertible value, Type targetType, IForma | |
// Conversions to Boolean | ||
public static bool ToBoolean([NotNullWhen(true)] object? value) | ||
{ | ||
return value == null ? false : ((IConvertible)value).ToBoolean(null); | ||
return value != null && ((IConvertible)value).ToBoolean(null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be a change in behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Certainly a change in code generation, arguably for the worse: https://csharp.godbolt.org/z/nrM7df3YP There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What makes you say it's "worse"? The code is nearly identical, just without the early exit for |
||
} | ||
|
||
public static bool ToBoolean([NotNullWhen(true)] object? value, IFormatProvider? provider) | ||
{ | ||
return value == null ? false : ((IConvertible)value).ToBoolean(provider); | ||
return value != null && ((IConvertible)value).ToBoolean(provider); | ||
} | ||
|
||
public static bool ToBoolean(bool value) | ||
|
Uh oh!
There was an error while loading. Please reload this page.