Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 701
Ismail Sahin Avatar asked Dec 20 '13 12:12

Ismail Sahin


People also ask

How do you automatically generate getters and setters in Visual Studio?

You just simply press Alt + Ins in Android Studio. After declaring variables, you will get the getters and setters in the generated code.

Can Eclipse generate getters and setters?

Right click on the file, select “Source” –> “Generate Getters and Setters…” Choose which field you want to generate, and click on “OK” button.

What can I use instead of getters and setters?

You may use lombok - to manually avoid getter and setter method. But it create by itself. The using of lombok significantly reduces a lot number of code.


1 Answers

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

like image 164
Sriram Sakthivel Avatar answered Oct 13 '22 11:10

Sriram Sakthivel