Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to change the order of constructors listed in IntelliSense in Visual Studio?

I have defined a class with multiple constructors so that the underlying interfaces are immutable once the object is instantiated. I would like one of the constructors to be the "default" constructor for when a user types the following in Visual Studio:

var obj = new MyClass(

Dim obj As New MyClass(

Currently when I go to instantiate the object, the constructors aren't listed (in Visual Studio IntelliSense) in the order I declared them in my class. Is there a way to mark up my constructors so that their methods appear in a particular order during instantiation in Visual Studio IntelliSense?

like image 246
Ben McCormack Avatar asked Aug 02 '10 20:08

Ben McCormack


People also ask

What does IntelliSense do in Visual Studio?

IntelliSense is a code-completion aid that includes a number of features: List Members, Parameter Info, Quick Info, and Complete Word. These features help you to learn more about the code you're using, keep track of the parameters you're typing, and add calls to properties and methods with only a few keystrokes.

How do I enable IntelliSense in Visual Studio?

To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.


2 Answers

There isn't a way to control the ordering within Visual Studio's Intellisense. If you do have multiple constructors (or methods), your only real control in terms of intellisense is to use EditorBrowsable with the appropriate EditorBrowsableState. This allows you to hide a contructor (or method) in intellisense, or only have it displayed in "advanced" mode, but does not allow you to reorder them.

However, in this situation, if you're targetting .NET 4, I'd recommend considering using a single constructor, and taking advantage of named and optional arguments.

like image 97
Reed Copsey Avatar answered Sep 20 '22 08:09

Reed Copsey


That's an interesting question, but I haven't heard of such capability. One option would be marking the other constructors as advanced or hidden.

ComponentModel.EditorBrowsable( ComponentModel.EditorBrowsableState.Advanced ) ComponentModel.EditorBrowsable( ComponentModel.EditorBrowsableState.Never )

like image 20
Jonathan Allen Avatar answered Sep 21 '22 08:09

Jonathan Allen