Say I am inheriting from a class with several "overloaded" constructors.
By any chance is there a short cut in Visual Studio which writes the constructors in the derived class with the same signatures as in the default class for me, with boilerplate code which calls MyBase.New(...) and plugs in the arguments for me?
EDIT: As far as I can find there is no such shortcut built-in, however there is one in resharper as suggested by Raymond.
Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Generate constructor in <QualifiedName> (with properties).
Generate a constructor Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there. In the Generate popup, select Constructor. In the Generate dialog that appears, select type members that should be initialized in the new constructor.
Using your example, the answer is: YES. The base constructor will be called for you and you do not need to add one. You are only REQUIRED to use "base(...)" calls in your derived class if you added a constructor with parameters to your Base Class, and didn't add an explicit default constructor.
In inheritance, the derived class inherits all the members(fields, methods) of the base class, but derived class cannot inherit the constructor of the base class because constructors are not the members of the class.
I don't know about a shortcut in a standard Visual Studio installation, but if you install the excellent Resharper plugin from jetBrains, it is Alt-Insert, C. I don't develop without it.
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