Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Resharper auto-formatting around certain blocks of code

In my C# development team, we want to share auto-formatting rules to respect our coding standards to have unified code formatting. I'm actually testing ReSharper and it's great but we have one rule in our standards that I can't seem to get around.

We use the HTMLTextWriter to render some HTML but we have a rule to indent the calls to reflect how they markup will be outputted.

For example :

protected override void RenderBody(HtmlTextWriter writer)
{
    writer.AddAttribute("class", "mystyle");
    writer.RenderBeginTag("div");
        writer.AddAttribute("class", "mystyle2");
        writer.RenderBeginTag("div");
            writer.Write("HELLO WORLD");
        writer.RenderEndTag();
    writer.RenderEndTag();
}

For now, when I reformat the code using ReSharper (or VS), the identation is removed.

Is there a way to add custom rule to prevent/disable reformatting around .RenderBeginTag function calls? Or is there another tool (other than ReSharper or in addition to ReSharper) that could do that?

like image 508
William Fortin Avatar asked Aug 16 '13 13:08

William Fortin


People also ask

How do I stop Visual Studio from auto formatting?

The solution was to go to 'Tools > Options > Text Editor > Basic > VB Specific' and turn 'Pretty Listing' OFF. Save this answer. Show activity on this post.

How do I paste without formatting in Visual Studio?

tip. Even if auto-formatting or auto-indenting on paste are enabled, you can paste code without reformatting it: press Ctrl+Z right after pasting, and only formatting will be undone. Note that by default, Visual Studio applies its own formatting rules for edited and pasted code.

How do I run ReSharper cleanup?

Press Ctrl+E F or choose ReSharper | Edit | Silent Cleanup Code from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there.


1 Answers

There's no way to tell R# to not clean up a part of the code and IMO you don't want to pollute your code with R#-specific markups. A workaround would be to indent your function calls in brackets like so:

 private void RenderBody(HtmlTextWriter writer)
 {
     writer.AddAttribute("class", "mystyle");
     writer.RenderBeginTag("div");
     {
         writer.AddAttribute("class", "mystyle2");
         writer.RenderBeginTag("div");
         {
             writer.Write("HELLO WORLD");
         }
         writer.RenderEndTag();
     }
     writer.RenderEndTag();
 }

R# won't reformat these blocks.

like image 170
slvnperron Avatar answered Oct 14 '22 01:10

slvnperron