views:

359

answers:

4

When editing a C# source file, I type

new {

Visual Studio auto-corrects it to

new object{

Is there a way to stop this behavior?

A: 

Have you checked your auto-complete options for ReSharper? I just tried this in a new (empty) class with the default ReSharper settings and couldn't duplicate it. What version of studio/ReSharper are you using?

Chuck
A: 

Try typing the left brace first, then going back and typing new. VS2008 does this for me (without ReSharper) and, if I remember, this is what I do. It's less typing than deleting the inserted "object".

tvanfosson
you're right, it's VS not RS. still, can this behavior be overridden?
Aidan Ryan
+1  A: 

What are you typing before the new {?

I've just tried it and it auto-completes with the object type, so if I type:

Button test = new {

it becomes:

Button test = new Button{

But if I type:

var test = new {

it leaves it alone.

I haven't configured my VS2008 install in any way.

ChrisF
This happens in the argument list of a method call, for example, in ASP.Net MVC for the object routeValues parameter of Action Link.
Aidan Ryan
Ah - I'd noticed it there, but didn't connect it with your question. @Richard's answer is the correct one.
ChrisF
+2  A: 

You can configure which characters being typed commit the current intellisense selection. In Tools | Options | Text Editor | C# | IntelliSense.

Remove "{" and ensure committed by the space bar is not checked.

Richard
Awesome, I'm off my bed of nails!
Aidan Ryan
I tried this but it did not stop either of the problems (auto-completion on space and on {), even after restarting. Perhaps it's Resharper?
BlueRaja - Danny Pflughoeft