Option to turn off brace placement enforcement in IDE?

  • Thread starter Thread starter carl.manaster
  • Start date Start date
C

carl.manaster

Hi, Group,

I prefer indenting braces with their block, thus:

public int Foo()
.....{
.....Bar();
.....}

[using dots because I know newsreaders tend to mess up whitespace]

But when I copy and paste such code in the IDE, it "fixes" the brace
placement for me, thus:

public int Foo()
{
.....Bar();
}

Please, leaving aside the issue of which way is "better", is there any
way to turn off this behavior? I'm happy to report that drag and drop,
at least, doesn't mess up my indentation.

Peace,
--Carl
 
Go to Tools->Options and select the C# editor in the left pane, then the
Formatting node.

Fiddling with these settings will certainly make the formatting change. I
don't think you can force it to do any more than not format what you've put
in though. Try uncheking "Automatically format completed constructs and
pasted source"

Checking "Leave open braces on same line as construct" gives you

if(thing)
{blah;
}

(ugh.... nasty!)

Your best bet is to not fight it and conform.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
Carl,

Have you checked under the options for the editor for C#? Under "Tools
| Options", then go to "Text Editor | C# | Formatting | General", there
should be an option called "Adjust indentation on paste". Uncheck that, and
you should be fine.

Hope this helps.
 
Thanks, Nicholas,

In my version the option is under

Text Editor | C# | Formatting

and is called

Automatically format completed constructs and pasted source

, but that certainly does the trick. Don't know why I didn't see it
myself. Thanks!

Peace,
--Carl
 
Thanks, Bob,

That does the trick.
Your best bet is to not fight it and conform.

I'm happy to conform to the standards of the team I'm working on, but
when the team is just me, I hate to be dictated to by a piece of
software.

Peace,
--Carl
 
Back
Top