The requested page is not available for the requested platform. You are viewing the content for Default platform.

Convert to Auto-implemented Property (convert all)

  • 2 min to read

Removes the backing store and converts all properties contained in the current class to Auto-implemented properties. The refactoring converts only properties that have a simple getter returning a field and a simple setter assigning a value to that field.

Availability

Available from the context menus or via shortcuts:

  • when the edit cursor or caret is on a property declaration statement, provided that the current class includes at least one more property with the backing store. The property should have a simple getter that returns a field, value and a simple setter that assigns that field a value.

Example

public class MyClass
{
  private int _Index;
  private string _Name;
  public string Name
  {
    get { return _Name; }
    set
    {
      _Name = value;
    }
  }
  public int Index
  {
    get { return _Index; }
    set
    {
      _Index = value;
    }
  }
}
Public Class MyClass
  Private _Index As Integer
  Private _Name As String
  Public Property Name() As String
    Get
      Return _Name
    End Get
    Set
      _Name = value
    End Set
  End Property
  Public Property Index() As Integer
    Get
      Return _Index
    End Get
    Set
      _Index = value
    End Set
  End Property
End Class

Result:

public class MyClass
{
  public string Name { get; set; }
  public int Index { get; set; }
}
Public Class MyClass
  Public Property Name() As String
  Public Property Index() As Integer
End Class

Screenshot

CSharpConvertToAutoimplementedPropertyConvertAll