Shortcut for creating constructor with base (C# Vi

2019-07-25 03:48发布

问题:

In Visual Studio C# you can, in a class, type ctor and then press Tab and Visual Studio will create a constructor for that class for me. Very convenient.

But is there a way (shortcut) to make Visual Studio generate all constructors with bases from its inherited class?

For example,

public class User:ClassA
{
    public User() {}
    public User(string S):base(S) {}
    public User(string S, int I):base(S, I) {}
    ...
}

回答1:

I do not have ReSharper and it is possible.

You can select your base class and press Shift + Alt + F10 and select Generate All:

I am not sure if it comes with the Visual Studio 2015 installation; maybe you need to add an extension. I am not sure which one of them it is required.

Following the extensions I have installed that maybe good candidates:

  • Application Insights Tools for Visual Studio
  • PowerShell Tools for Visual Studio 2015
  • Productivity Power Tools 2015
  • Snippet Designer
  • Visual Studio Extensibility Templates