Results 1 to 5 of 5

Thread: IDE0075 How do I simplify this condition expression?

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    IDE0075 How do I simplify this condition expression?

    Is this what VS wants me to do here?

    Code:
    //ckOTNew.Checked = drTrips.IsOTNull() ? false : drTrips.OT;
    ckOTNew.Checked = drTrips.IsOTNull() && drTrips.OT;
    I feel like I had to think about that too much and NOT simplifying it makes it easier for me as a human being to write/read (and given the kind of brain I have, LOL)
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: IDE0075 How do I simplify this condition expression?

    That seems like reverse logic to me.. The top one says

    If drTrips is OTNull then it is false, otherwise it is the value of drTrips.OT.

    The second one is saying

    if drDrips isOTNull AND drDrips.OT


    So in the first, if drTrips is not OTNull, then it returns the value of drTrips.OT, but in the second one, if drTrips is not OTNull, then the value is always going to be false.

    I would assume it should be

    Code:
    ckOTNew.Checked = !drTrips.IsOTNull() && drTrips.OT;
    However, these are all just warnings, so use whatever is clearer for you.

    Also, I'm not sure if it is resharper that adds this for me, but in VS, if there is a warning for code formatting like you've been posting, usually you can hover over relevant code and a lightbulb will come up. You can then ask VS to refactor the code for you to see what it means.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: IDE0075 How do I simplify this condition expression?

    The fact that you seem to have reversed part of the logic may have been part of the reason but it can also be how you read it. Think about what this is actually saying:
    Code:
    ckOTNew.Checked = !drTrips.IsOTNull() && drTrips.OT;
    It says that ckOTNew is checked if and only if the OT column is not NULL and the OT column is True.

  4. #4

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: IDE0075 How do I simplify this condition expression?

    Quote Originally Posted by kfcSmitty View Post
    ...but in the second one, if drTrips is not OTNull, then the value is always going to be false.
    LOL, actually in the second one I am going to exception!
    So this is kind of what I mean. Maybe I should not rewrite this because I rewrote it wrong and if I hadn't asked and wasn't testing it would've been released live like this.

    So yes, the correct one is: ckOTNew.Checked = !drTrips.IsOTNull() && drTrips.OT; because the second part of the condition won't be evaluated since the first part is false and it can stop there and no danger of exceptioning.
    So I either have to be careful rewriting these making sure I don't change the logic or prefer that it remain unsimplified because to me it's easier to understand written out in longhand.

    @kfcSmitty - I don't get a lightbulb; I get what's below:

    Name:  IDE0017 Quick Actions and Refactoring.jpg
Views: 421
Size:  19.1 KB
    Last edited by MMock; Jan 14th, 2021 at 10:55 AM.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  5. #5
    PowerPoster kfcSmitty's Avatar
    Join Date
    May 2005
    Posts
    2,248

    Re: IDE0075 How do I simplify this condition expression?

    Ah yeah, looks like it is a feature of resharper.

    You could try the 30 day trial, it may help you determine which formatting you like or not.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width