I'm trying to create a property that will allow the setting of a last name based on a variety of inputs. The code that calls this is parsing a name field. In some instances it will have a single last name, in others, a array of last names that need to be concatenated. I want to keep my concatenation code in a single place to make maintenance easier.
Here is my code, which of course doesn't work:
Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal value As String)
_LastName = value
End Set
End Property
Public WriteOnly Property LastName() As String()
Set(ByVal value As String())
For Each word As String In value
_LastName &= word & " "
Next
_LastName = _LastName.Trim
End Set
End Property
I've tried numerous variations on this, even putting multiple Set in the same Property, but nothing seems to work. There must be some way to take in an array and a single instance value. The compiler clearly knows if the incoming object is an array or not.
I tried working with just a property of type String(), but then I can't return a String. The only solution that I can think of is differently named properties, which makes using the class more difficult, or a whole bunch of Subs and Functions overloading each other.
Suggestions?
Chris