Shrinking "if" statment

Hi All,

I wonder if any one know how to Shrink "if" statment.

like we can do if function ( the plus / minus sign in the left side ).

It's make me crazy, because I have a lot of lines of code inside the bracket.

AND if this option is exist , it's will be very useful.

I don't want to use the #region Options.

Please Help

BOAZ.



Answer this question

Shrinking "if" statment

  • AlEvan

    I am not sure if I understand what you mean by shrinking an if statement are you saying that you have alot of code to execute on either side of the condition -

    if (test) { LOTS OF CODE HERE }

    else { EVEN MORE CODE HERE }

    I contend you may need to refactor and employ some object oriented techniques.

    Google "Replace Conditional with Polymorphism"

    get Fowler's Refactoring: Improving the Design of Existing Code

    and get the original Gang Of Four



  • JaySch_MS

    You probably don't want to hear this, but another solution would be to extract those if branches into methods, making your code more readable yourself instead of relying on the IDE to do it:


    if (a) {
    // Do action A
    ...
    } else {
    // Do action B
    ...
    }

    -->

    if (a) {
    DoA();
    } else {
    DoB();
    }

    ...



  • Gavin Clark

    Boaz -

    Unfortunately, there's no real way to do this today -- although we have it on our plate as a suggestion for a future version.

    One way you can somewhat get the behavior you want is to go to Edit | Outlining | Stop Outlining. Now a new option will appear on the outling menu (Edit | Outlining) and Choose "Hide Selection." This will create the +/- collapsable region around the if block that you're looking for.

    HTH,

    Karen



  • AshishM

    Thanks Karen,

    It's work - Please insert it to the future version.

    Regards,

    Boaz Shalev.


  • Ed Andersen

    Dear Blair,

    like the #region Options that make it possible to open/close section of code,

    OR the plus/minus sign that give you the option to open/close the function code.

    My question if there is a way, to open/close an "if" or "case" statment because I have a lot of code rows and it's make me crazy.

    Thanks Again

    BOAZ.


  • _Carlos_

    cool. . . another way the C# IDE blows away the VB IDE.

    still I contend the code needs refactoring.



  • Shrinking "if" statment