Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shortcut to generate field from property in Visual studio

Is there any shortcut in VS to define a field from corresponding property?

like image 309
vkg Avatar asked Jul 31 '14 07:07

vkg


People also ask

Which shortcut to create a property declaration with Get and Set?

Here I am Showing You That How You Can Get & Set Property Using Shortcut In Visual Studio. Then it will automatically display intelligence & from that select "prop" & then press TAB key from your keyboard then it will automatically add a code snippet of get & set property.

How do I access properties in Visual Studio?

You can find Properties Window on the View menu. You can also open it by pressing F4 or by typing Properties in the search box. The Properties window displays different types of editing fields, depending on the needs of a particular property.

How do you add a property in VS code?

You could type "prop" and then press tab twice. That will generate the following. You can also get the full property typing "propfull" and then tab twice. That would generate the field and the full property.

What is a field in Visual Studio?

The Field List displays the hierarchy of fields contained in tables and/or views of the dashboard data source, and allows you to create calculated fields. The Field List is shown in the Visual Studio IDE, along with other IDE windows, when you edit a dashboard at design time.


1 Answers

if you mean to generate a backing store for an auto generated property:

 public string MyProperty { get; set; }

To:

 public string _myProperty;
 public string MyProperty { 
      get { return _myProperty; } 
      set { _myProperty = value; } 
 }

Then there is no shortcut that does that in Visual Studio. Refactoring tools like Resharper and CodeRush offer this feature.

  • In DevExpress CodeRush Refactor it's under ctrl+`, Convert to Property with Backing Store.
  • In Resharper it's under alt+enter, To Property with Backing Field.

In Visual Studio, there is the "Encapsulate field" refactoring that works the other way around ctrl+r,e.

 public string _myProperty;

To:

 public string _myProperty;
 public string MyProperty { 
      get { return _myProperty; } 
      set { _myProperty = value; } 
 }
like image 163
jessehouwing Avatar answered Oct 12 '22 04:10

jessehouwing