Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Visual Studio 2015 to create public properties when hitting "Ctrl + ."? [duplicate]

Well, I use visual studio 2015 CE, update 2. One productivity hack I usually do is that I create empty model classes like:

public class PersonModel
{
}

and then use them in a select expression like:

db.People.Where(p => someCondition)
.Select(p => new PersonModel
{
    Id = p.Id,
    Name = p.Name,
    //set other properties
}).ToList();

Then I go to the yet non-existing properties Id and Name, ... and press Control+. to ask visual studio to generate property Id for me. All great, but it will create:

public int Id { get; internal set; }

and if I use the same method in an asp.net webapi model binding, the binding will fail silently and give me Id = 0.

So my question is: is there any option to ask VS to create public setter, i.e.:

public int Id { get; set; }
like image 537
Alireza Avatar asked Nov 22 '22 07:11

Alireza


1 Answers

So my question is: is there any option to ask VS to create public setter, i.e.:

No, there is no way to modify the shortcut to automatically add the property with a public set. Although your productivity hack is neat, your best bet is to create it yourself.

like image 107
Restnom Avatar answered Nov 23 '22 22:11

Restnom