7

I'm wondering if there's a shortcut so that if I have an Complex object, I can do

var myObject = new SomeObject() {

then type a shortcut so I get this:

var myObject = new SomeObject()
{
 Name = "",
 Age = 0,
 Height = 0,
 etc.
}

As it would speed up my development time massively. I do a lot of stuff with SOAP and some of the objects have 20-30 properties in.

Intellisense is great to bring them up one by one, but if you need to skip some then you start having problems.

I have Resharper, if that adds an option also.

NibblyPig
  • 51,118
  • 72
  • 200
  • 356
  • What about [Code Snippets](https://msdn.microsoft.com/en-us/library/ms165392.aspx) ? – Patrik Jul 07 '15 at 11:04
  • as far as I know, you cannot autocomplete an entire initializer in one go other than going on one-by-one properties hitting control+space. If this is any help, you may want to check out creating macros to do that for you – Eon Jul 07 '15 at 11:05
  • 5
    Why would you want to do that? For value types, you get the default value anyway. If you want `string.Empty` for a string, simply initialize it inside the class's default constructor. – Yuval Itzchakov Jul 07 '15 at 11:07
  • 1
    I will go through and quickly populate all the fields myself, usually from another object, eg. `name = someObj.Name` etc. and having to press ctrl+space and navigate to the property each time is very time consuming – NibblyPig Jul 07 '15 at 11:08
  • do you want to copy from another object completely ? then Clone. if there is some king of algorithm for setting objects then use method. – M.kazem Akhgary Jul 07 '15 at 11:12
  • This won't answer your question, but have you thought about making it "the other way around", creating a constructor with all the public properties in the `SomeObject`. You can easily create such a constructor with `Alt+Insert` in your class. – Markus Jul 07 '15 at 14:10
  • same question here: [Is there a way, at design time, to initialize an object with all properties in Visual Studio 2010?](https://stackoverflow.com/questions/9083379/is-there-a-way-at-design-time-to-initialize-an-object-with-all-properties-in-v) – PLopes Nov 15 '19 at 13:26

0 Answers0