7

Is there a way to lock or freeze a part of code against formatting in Visual Studio?

I want to protect the following code :

Method("This is a long text", 12 , true  );
Method("Hi",                  558, true  );
Method("Short text",          1  , false );

to be formatted as:

Method("This is a long text", 12, true);
Method("Hi", 558, true);
Method("Short text", 1, false);

but still be able to format the rest of the document.

default
  • 10,975
  • 8
  • 63
  • 100
Mohsen Sarkar
  • 5,710
  • 7
  • 43
  • 84

2 Answers2

0

You can turn it off completely (Options->TextEditor->Basic->General) uncheck off Pretty Listing. And under Options->Text Editor->C#->Formatting turning off options there.

But, sadly, there isn't any built-in option to selectively prevent formatting a portion of code.

hometoast
  • 11,293
  • 4
  • 39
  • 57
  • I doubt.. there must be a way to achieve that. Maybe not directly as a option but maybe some plugin do that – Mohsen Sarkar Feb 15 '13 at 13:07
  • Even R# doesn't have a way to mark a selection do-not-format. (http://stackoverflow.com/questions/2176429/is-there-a-way-to-mark-up-code-to-tell-resharper-not-to-format-it) – hometoast Feb 15 '13 at 13:09
0

The ReSharper formatting style, is the key for your problem.

spajce
  • 6,968
  • 5
  • 27
  • 44
  • Can you post link to some screenshot from formatted code by ReSharper ? – Mohsen Sarkar Feb 15 '13 at 13:13
  • 1
    Resharper has LOTS of options for formatting. But not for protecting one section of code. (http://stackoverflow.com/questions/2090354/is-there-a-way-to-keep-resharper-from-formatting-a-region-of-code) – hometoast Feb 15 '13 at 13:16
  • it might be this feature will be added is in another version. we will wait `:)` – spajce Feb 15 '13 at 16:09