Rory Becker - DevExpress CodeRush Blog

September 2014 - Posts

  • New CodeRush Plugin – CR_CollapseXML

    Another new plugin! This one requested by a customer so they could collapse some XML (or HTML) on command.

    Is there any way to have CodeRush collapse HTML or XML elements which have a ‘name’ or ‘id’ attribute?

    The theory behind this is that those elements with an id or name attribute, are typically the ones that hold the high level structure. Collapsing these items will cause the structure of the HTML to be revealed.

    In some ways it ‘s like CodeRush’s own Collapse to Projects functionality in solution explorer.

    The user wishes to get a high level view of their HTML so that they can decide which area to drill back down into.

    Now CodeRush doesn’t naturally support this functionality for HTML/XML out of the box, but you guys know me by now Smile

    Yeah I wrote a plugin Smile

    CollapseXML for CodeRush

    CollapseXML works (despite it’s name) on both HTML and XML. It adds a new command (CollapseXML) which you can bind to any key you like.

    Once installed and configured, simply place your caret within an XML or HTML file, and invoke the command using your configured key.

    CodeRush will happily collapse your XML/HTML from…

    HTMLExpanded

    … to…

    HTMLCollapsed

    Availability

    This plugin is available from either The Visual Studio Gallery or from GitHub

    The source is available on Github

  • New CodeRush Plugin – Sort Format Tokens

    Some programmers feel that they have some sort of very minor OCD. Despite no real rational reason, they feel that certain things should be a certain way. The world seems out of place, slightly of kilter, slightly more irritating or distracting when these things are not quite as they would like them to be.

    Of course when I say ‘Some programmers’, I certainly include myself in that group.

    Today’s plugin is kind of an OCD plugin. It’s just my personal attempt to scratch a little itch. I’d be amazed if this helps anyone else at all. I’m just putting it out there as an example of just how flexible CodeRush can be.

    When I set out to create it, I had no other purpose in mind, than the appeasement of that part of my brain, which objected every time I didn’t adjust my code to this specific pattern.

    That said, the plugin does have some benefits as a natural consequence of the way it works.

    Sort Format Tokens

    This plugin operates on a subset of the String.Format calls.

    Consider the following call:

    SortFormatTokensExample1

    It’s simple and it does exactly what you need it to. However over time you might feel the need to add more elements to the message:

    SortFormatTokensExample2

    Something about this statement irks me. Something just doesn’t sit right. So I find myself rewriting it

    SortFormatTokensExample3

    This new code operates exactly the same as the old code. There isn’t even a performance benefit here.

    However my particular brand of very minor OCD feels better and I’m able to scan through the code and comprehend it quicker.

    The Problem

    Changing one statement into the other is a manual task. There is the risk of typos and logic errors, and of course it takes time to achieve.

    Not very much time I guess, but every moment that I spend thinking about this sort of thing, is less time spent on solving business problems and adding value.

    Therefore I did what I usually do when I spot a coding task I’d prefer not to have to do manually, which has an predictable pattern to it….

    I wrote a plugin Open-mouthed smile

    The Solution –> Sort String Tokens for CodeRush

    This plugin does exactly what it says on the tin.

    It rewrites the a String.Format call so that…..

    • The string tokens are (where appropriate) in numerical order.
    • The arguments that follow the string are in the same matching order.

    Simply place your caret within the first argument of a String.Format call and choose 'Sort Format Tokens’ from the Code subsection of your CodeRush\Refactor Smart tag menu.

    SmartTagMenuSortFormatTokens

    Bonus Features

    Beyond the original spec of “Sort my string tokens so that they look nice”, SortFormatTokens is also careful to correctly interpret several corner case scenarios.

    • It deals correctly with sequences of tokens with missing items.
      Gaps in the sequence are removed.  “{1} – {3} – {6}”  becomes “{0} – {1} – {2}”.
    • It deals correctly with string tokens that have formatting information.
      Formatting information is retained within the renumbered token. “{1:00} – {0} – {2}” becomes “{0:00} – {1} – {2}”
    • It deals correctly with duplicate usage of a token within a string.
      The 2nd and further instances of any given token are renumbered the same way as the first instance. “{1} – {0} – {1}” becomes “{0} – {1} – {0}”.
    • It also removes any unreferenced arguments from the call, optimizing your call to be faster in the process.

    Where can I get this wonderful plugin from?

    As usual this plugin is available from the Visual Studio Gallery and from GitHub.

    The source code is available on GitHub

LIVE CHAT

Chat is one of the many ways you can contact members of the DevExpress Team.
We are available Monday-Friday between 7:30am and 4:30pm Pacific Time.

If you need additional product information, write to us at info@devexpress.com or call us at +1 (818) 844-3383

FOLLOW US

DevExpress engineers feature-complete Presentation Controls, IDE Productivity Tools, Business Application Frameworks, and Reporting Systems for Visual Studio, along with high-performance HTML JS Mobile Frameworks for developers targeting iOS, Android and Windows Phone. Whether using WPF, ASP.NET, WinForms, HTML5 or Windows 10, DevExpress tools help you build and deliver your best in the shortest time possible.

Copyright © 1998-2017 Developer Express Inc.
All trademarks or registered trademarks are property of their respective owners