Skip to content
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

Request: Simplify comparison against nullable structs #373

Closed
IanKemp opened this issue May 25, 2018 · 2 comments
Closed

Request: Simplify comparison against nullable structs #373

IanKemp opened this issue May 25, 2018 · 2 comments

Comments

@IanKemp
Copy link

IanKemp commented May 25, 2018

decimal? baz = null;

if (baz != null && baz > 0) // no RCS1146
{
    Console.WriteLine("baz");
}
@josefpihrt
Copy link
Collaborator

RCS1146 is called UseConditionalAccess. Where do you want to use conditional access in your code?

@IanKemp
Copy link
Author

IanKemp commented May 31, 2018

Apologies Josef, I got confused - this is actually a feature request.

Essentially, the following pattern:

Nullable<T> thing;
T thingValue;

var validValue = thing.HasValue /* or "thing != null" */ && thing.Value > thingValue;

can be simplified to:

Nullable<T> thing;
T thingValue;

var validValue = thing > thingValue;

and it would be useful if Roslynator could add this.

@IanKemp IanKemp changed the title RCS1146 doesn't trigger for Nullable<T> Request: Simplify comparison against nullable structs May 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants