views:

19

answers:

1

Is it correct to correct properties values on the fly?

for example: (note the .ToLower)

Public Property X() As String
   Get
      Return _x.ToLower
   End Get
   Set(ByVal Value As String)
      _x = value.ToLower
   End Set
End Property
+1  A: 

There is nothing incorrect about standardizing your properties in getter/setters. Without any context of what X represents it is hard determine if a property is the right way to access and update the value of X. Depending on the application, it might make sense to not have a public setter at all but instead have a method such as CustomerRequestedXToChange(XUpdatedValue as String)

Some improvements to your code though:

  1. Be sure that _x is private so that no other classes can modify the value.
  2. Only perform ToLower on the setter, not both. As long as you follow the next convention that should work fine.
  3. All calls to _x within this class should go through X, that way the value of _x will be correct.
DavGarcia
Thank you, it was just a quick example.
Sein Kraft