Style of generated properties Vs C#

Viewed 72

How can I change the style of the properties that are generated by Visual studio?

This is what I get :

 public int Population {
            get {
                return _Population;
            }

            set {
                _Population = value;
            }
        }

This is what i want :

public string Population
{
    get{return _Population;}
    set{_Population=value;}
}

enter image description here

1 Answers

You are looking for existing propfull code snippet.

So type propfull and press Tab twice your desired format will be created.

private int _Population;

public int Population
{
    get { return _Population; }
    set { _Population = value; }
}

**Edited:**Control the way code is formatted after Refactor->Encapsulate Field

Please note that Language Service formats code once its added using code-snippets. Hence, one can change the formatting of the code inserted after Refactor->Encapsulate Field by changing option Leave block on single line as unchecked. Its shown in image below.

enter image description here

Related