Remove Setter Guard Clause

Removes the value changed check at the start of a property setter.

Availability

Available from the context menu or via shortcuts:

  • when the edit cursor or caret is on the setter of a property, or on the setter's if-statement. The setter should contain the if-statement. The if-statement should have a single condition, which checks whether the setter parameter is equal to the assigned field.

Example

protected int _PropertyName;
public int PropertyName
{
    get 
    {
        return _PropertyName; 
    }
    set
    {if (_PropertyName == value)
            return;
        _PropertyName = value;
    }
}
Public Property PropertyName() As Integer
    Get
        Return _propertyName
    End Get
    Set(ByVal Value As Integer)If _propertyName = Value Then
            Return
        End If
        _propertyName = Value
    End Set
End Property

Result:

protected int _PropertyName;
public int PropertyName
{
    get 
    {
        return _PropertyName; 
    }
    set
    {_PropertyName = value;
    }
}
Protected _propertyName As Integer
Public Property PropertyName() As Integer
    Get
        Return _propertyName
    End Get
    Set(ByVal Value As Integer)_propertyName = Value
    End Set
End Property

Screenshot

rsRemoveSetterGuardClause