How do I generate a constructor from class fields using Visual Studio (and/or ReSharper)?

前端 未结 12 1849
有刺的猬
有刺的猬 2020-11-27 12:54

I\'ve gotten accustomed to many of the Java IDEs (Eclipse, NetBeans, and IntelliJ IDEA) providing you with a command to generate a default constructor for a class based on t

12条回答
  •  感动是毒
    2020-11-27 13:37

    I'm using the following trick:

    I select the declaration of the class with the data-members and press:

    Ctrl+C, Shift+Ctrl+C, Ctrl+V.

    • The first command copies the declaration to the clipboard,
    • The second command is a shortcut that invokes the PROGRAM
    • The last command overwrites the selection by text from the clipboard.

    The PROGRAM gets the declaration from the clipboard, finds the name of the class, finds all members and their types, generates constructor and copies it all back into the clipboard.

    We are doing it with freshmen on my "Programming-I" practice (Charles University, Prague) and most of students gets it done till the end of the hour.

    If you want to see the source code, let me know.

提交回复
热议问题