← back to index

S2376 — Write-only properties should not be used

Language: VB.NET  |  Type: CODE_SMELL  |  Severity: Major

Tags: pitfall

Why is this an issue?

Properties with only setters are confusing and counterintuitive. Instead, a property getter should be added if possible, or the property should be replaced with a setter method.

Noncompliant code example

Module Module1
    WriteOnly Property Foo() As Integer ' Non-Compliant
        Set(ByVal value As Integer)
            ' ... some code ...
        End Set
    End Property
End Module

Compliant solution

Module Module1
    Sub SetFoo(ByVal value As Integer)  ' Compliant
        ' ... some code ...
    End Sub
End Module