5

Does anyone know how to "scaffold" or "generate" a constructor block for all of an objects properties? I've got VS2010 with Resharper and am looking to generate something like:

    public Customer CustomerB = new Customer
                                    {
                                        firstName = "",
                                        middleName = "",
                                        lastName = "",
                                        additionalPhone = "0",
                                        address1 = "",
                                        address2 = "",
                                        birthDate = new DateTime(),
                                        cellPhone = "",
                                        city = "",
                                        driverLicenseNumber = "",
                                        driverLicenseState = "",
                                        emailAddress = "",
                                        country = "",
                                        fax = "",
                                        grossIncome = 0,
                                        education = null,
                                        leadRequest = null
                                    };

Where I can then double back and fill in the blanks so to speak. Everything i've found is all DatabaseFirst and Getter/Setters Class Properties...

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
James Troutman
  • 211
  • 1
  • 2
  • 5
  • So you already have a class with all those properties, and you want to generate the `new` using object initializer syntax, right? – AakashM Jul 03 '12 at 08:09
  • you can use a macro, someone has written one to do a constructor (ie what resharper does ootb) which you could modify for what you want to do. http://stackoverflow.com/questions/2976363/how-do-i-generate-a-constructor-from-class-fields-using-visual-studio-and-or-re – wal Jul 03 '12 at 12:52

1 Answers1

1

I think it is not possible to generate object initializer for all properties with VS and ReSharper. You need to press Ctrl+Space for every property selection.

brgerner
  • 4,287
  • 4
  • 23
  • 38