1

I have class and there are a lot of properties in it. Is there a functionality of visual studio to reach all the properties easily. I do not want to use a constructor.

This is the class:

Assignment a = new Assignment()
{

}

And this is what I want to do automaticly so i can fill the values:

Assignment a = new Assignment()
{
     prop1 = ,
     prop2 = ,
     prop3 = ,
     prop4 = ,
     prop5 = 
     //...
};
asdawf212
  • 23
  • 3
  • Considering adding a constructor to `Assignment`. Then you can do them on the first line without explicitly spelling out each parameter / property name. – mjwills Jul 31 '18 at 11:37
  • So you are asking for a refactor functionality of Visual Studio that populates every property to make it "settable"? – Rand Random Jul 31 '18 at 11:39
  • 2
    I don't believe there is a native function. Re-Sharper lists all properties if you press Control-Space, so you can choose the next property. I have not seen a better way (yet). – 4ndy Jul 31 '18 at 11:41
  • 1
    Why specifically do you not want to use a constructor? – mjwills Jul 31 '18 at 11:48
  • Because I don't require to fill all of the fields. This is just for unit testing code. – asdawf212 Jul 31 '18 at 12:00
  • You know you can have two constructors? One with all the fields and a default one (with none of them)? – mjwills Jul 31 '18 at 12:07
  • Yes reflection, though if you dont want to use a constructor, i doubt you will want to use reflection more – TheGeneral Jul 31 '18 at 12:27
  • See https://stackoverflow.com/questions/48464576/shortcut-to-instantiate-an-object-in-visual-studio – Sergey Vlasov Aug 01 '18 at 05:47

1 Answers1

1

If you need to ensure that all properties are filled, I would use a constructor.

If you do not require all properties or prefer to use an object initialiser, then the closest solution would be ReSharper's Control+Space, which brings up each property. As you select them (and assign them) the list gets shorter, so you only select from the remaining unassigned properties. I am not sure if there is a better way.

4ndy
  • 550
  • 1
  • 9
  • 23