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?
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.
To access this options page, choose Tools > Options, and then choose Text Editor > C# > IntelliSense.
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.
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 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With