views:

1501

answers:

4

Short version- is there a way to turn off Visual Studio Intellisense for the object keyword.

Long version- I'm using Visual Studio 2008 and I'm basically using anonymous types. I begin typing something like:

Assert.AreEqual("/SomePath/Stuff", GetOutboundUrl(

I type in new {

Then I see that Visual Studio has recognised that the method GetOutboundUrl takes an object and changed the code to new object{. Now must of the time this is great, except for two reasons:

1) I rarely have code that uses the type object.

2) I am actually trying to create an anonymous type not a object, so this feature is actually serving as a hindrance.

The signature for GetOutboundUrl is as follows (from the book Pro ASP.NET MVC framework if anyone is interested):

private string GetOutboundUrl(object routeValues)

I am wondering if there is a way to turn this feature off but only for the keyword object- I would like to see if I actually miss the autocomplete on object (personally I don't think that I will).

I realise that I can turn this off for all keywords by unchecking "Place keywords in completion lists", but I only want to turn it off for object.

+1  A: 

Without changing an actual Visual Studio setting (which I doubt exists), you could type "new ", then ESC, followed by "{". It's not ideal, but it keeps you from having to delete the word "object" each time.

You could address this particular situation by editing the options: "Text Editor" -> "C#" -> "IntelliSense" => "Committed by typing the following characters:". Remove the "{".

John Fisher
Pressing escape is my current solution to the problem- thanks for the suggestion though- it might be useful to others reading about this.
RichardOD
I actually tried removing "{" as suggested above, restarted Visual Studio, and it still added "object" when I typed "{".
RedFilter
OrbMan, when I ran the test, I removed both "{" and "}". Does that work for you? (It did for me.)
John Fisher
+1  A: 

What I do when intellisense gets annoying is comment out a few blank lines, write my code on those lines, as comments, then uncomment them when I'm through. Voila, you can write whatever you want and intellisense will not butt in. Other times, when you want intellisense, it's not disabled. I hope this helps someone out there!

+2  A: 

[apologies for answering instead of commenting-- I'm a newbie and don't have enough rep to comment yet...]

FYI, related (dupe?) qustion: http://stackoverflow.com/questions/717252/how-do-i-stop-visual-studio-from-inserting-object-when-i-type-new. Accepted answer on that question is same as suggestion above: remove "{" from the list of chars in Tools | Options | Text Editor | C# | IntelliSense.

FWIW, the "remove { from intellisense dialog" solution works for me on VS2008 with SP1. John, does this solution work for you?

Per OrbMan's comment above, this fix may not work for everyone. OrbMan, are you on VS2008 SP1 too or something else?

Justin Grant
Interesting- thanks I will check it out.
RichardOD
That's a good solution. +1. You need only one more up to and you can comment like crazy!
HuBeZa
+1  A: 

I made a ReSharper Live template:

Shortcut: new

Contents: 
new { $END$ }

Now I can type n-e-w-TAB and I end up with "new { }" and my cursor between the curlies.

It's not ideal, but it's better.

Lance Fisher
I have one similar to that for JavaScript for creating anonymous functions, func-TAB create function(){$END$}
Chris Brandsma