H
hawbsys
I'm wondering what the best way to make a property value cascade down
through a hierarchy would be. Say
you have a MileageRate property which is always set at a default rate
at the Application level. But there is the option to override the top
level rate with a rate specific to a customer type. And so on down the
hierarchy.
Application
-> CustomerType
-> Customer
-> Project
Is there a neat way to do this? I have been playing with classes &
properties per the below:
Public Class Customer
Private _MileageRate As Nullable(Of Single)
Public Property MileageRate() As Nullable(Of Single)
Get
If _MileageRate.HasValue Then
Return _MileageRate
Else
Return Me.CustomerType.MileageRate
End If
End Get
Set(ByVal value As Nullable(Of Single))
if value.HasValue then
_MileageRate = value
End If
End Set
End Property
[...]
End Class
But I'm not sure this is the neatest way forward. For one thing it
doesn't databind smoothly, since a customer with no particular
MileageRate will have his MileageRate set to match the cascaded down
value as soon as you bind the MileageRate property to a textbox on a
form. Which isn't desirable because thereafter, if the Application
MileageRate is modified, he will still be set to the original value.
It will look like an intentional override.
There must be slicker ways of doing it.
Hawbsl
through a hierarchy would be. Say
you have a MileageRate property which is always set at a default rate
at the Application level. But there is the option to override the top
level rate with a rate specific to a customer type. And so on down the
hierarchy.
Application
-> CustomerType
-> Customer
-> Project
Is there a neat way to do this? I have been playing with classes &
properties per the below:
Public Class Customer
Private _MileageRate As Nullable(Of Single)
Public Property MileageRate() As Nullable(Of Single)
Get
If _MileageRate.HasValue Then
Return _MileageRate
Else
Return Me.CustomerType.MileageRate
End If
End Get
Set(ByVal value As Nullable(Of Single))
if value.HasValue then
_MileageRate = value
End If
End Set
End Property
[...]
End Class
But I'm not sure this is the neatest way forward. For one thing it
doesn't databind smoothly, since a customer with no particular
MileageRate will have his MileageRate set to match the cascaded down
value as soon as you bind the MileageRate property to a textbox on a
form. Which isn't desirable because thereafter, if the Application
MileageRate is modified, he will still be set to the original value.
It will look like an intentional override.
There must be slicker ways of doing it.
Hawbsl