Ismail Sahin
Ismail Sahin

Reputation: 2710

Is there a way of generating getter, setter functions in visual studio 2012 like in eclipse

I had looked up solutions here C# shortcut or shorthand getter setter but when I implement one of solutions

visual studio generates code like

private int myVar;

public int MyProperty
{
    get { return myVar; }
    set { myVar = value; }
} 

what I want vs auto getter setter generator is to create getter setter for all of my variables and depending using their name like

private int id;

public int Id
{
    get { return id; }
    set { id= value; }
}

Is this possible?

Upvotes: 6

Views: 20445

Answers (2)

Brendan
Brendan

Reputation: 1247

Type propfull tab tab

Then double-click on the variable "myVar" and replace it with what you want. VS will then replace the all other instances of it. You can also double-click on the type to change that and VS will change the auto code accordingly.

You can then edit the property name

Upvotes: 0

Sriram Sakthivel
Sriram Sakthivel

Reputation: 73442

Yes, Just create a field then Refactor->Encapuslate Field. Shortcut is ctrl + R, E

Upvotes: 7

Related Questions