C
Chris Bernholt via .NET 247
I'd like to create a structure such as:
Public Structure MyType
Private m_variable As String
Public Property Variable() As String
Get()
return m_variable
End Get
Set (ByVal Value As String)
If validateVariable(Value) Then
m_variable = Value
Else
Throw New ArgumentException("Variable invalid")
End If
End Set
End Property
Private Function validateVariable(ByVal theVar as String)
'Do validation here
End Function
End Structure
and be able to use it like
Dim mt as MyType
Try
mt = "123abc"
Catch
'Handle exception
End Try
instead of
Dim mt As MyType
Try
mt.Variable = "123abc"
Catch
'Handle exception
End Try
Is this possible, and if so, what changes do I need to make?
Thanks
-- Chris
Public Structure MyType
Private m_variable As String
Public Property Variable() As String
Get()
return m_variable
End Get
Set (ByVal Value As String)
If validateVariable(Value) Then
m_variable = Value
Else
Throw New ArgumentException("Variable invalid")
End If
End Set
End Property
Private Function validateVariable(ByVal theVar as String)
'Do validation here
End Function
End Structure
and be able to use it like
Dim mt as MyType
Try
mt = "123abc"
Catch
'Handle exception
End Try
instead of
Dim mt As MyType
Try
mt.Variable = "123abc"
Catch
'Handle exception
End Try
Is this possible, and if so, what changes do I need to make?
Thanks
-- Chris