Class.Property.SubProperty.Value
I'm using reflection to iterate through the path grabbing the sub-properties down to the "leaf" property at which point the value is returned. The basic concept is this:
Expand|Select|Wrap|Line Numbers
- Function GetValue(ByVal FreightBill As IFreightBill, ByVal ValuePath As String) As Double
- Dim AssemblyName As String = Reflection.Assembly.GetExecutingAssembly().GetName.Name
- Dim PathNodes As List(Of String) = ValuePath.Split(".").ToList
- If PathNodes(0) <> AssemblyName Then PathNodes.Insert(0, AssemblyName)
- Dim CrntInstance As Object = FreightBill
- For i As Integer = 2 To PathNodes.Count - 1
- Dim CrntType As Type = CrntInstance.GetType()
- Dim CrntProperty As String = PathNodes(i)
- Dim dynProperty As Reflection.PropertyInfo = CrntType.GetProperty(CrntProperty)
- Dim CrntValue = dynProperty.GetValue(CrntInstance, _
- System.Reflection.BindingFlags.GetProperty, _
- Nothing, _
- Nothing, _
- Nothing)
- CrntInstance = CrntValue
- Next
- Return CrntInstance
- End Function
Expand|Select|Wrap|Line Numbers
- Public Property MyIncorrectlyNamedProperty() As String Implements IMyInterface.ActualPropertyName
So my question I guess is in order to prevent possible problems with VB programmers calling instance properties by incorrect names, what can I do about this? Other than rapping them on the knuckles with a ruler and telling them not to do that...