Is there a mechanism for addressing object properties (or constants) in a manner that is similar to the techniques used for identifying folder items?
So, for example, is it possible to do something like:
Object.Property(“theName”) = value
The obvious first question is “why not just use Object.theName?” It’s because I have a large number of properties to set and I would like to create a generic routine to do so.
Consider 100 sets of the following information.
Object.Property1 DataName1, DataValue1
Property1 and DataName1 have identical values. The object is to get each DataValue into its comparable Property. If each Property could be addressed by using the (identical) DataName, values could be quickly assigned.
Not directly. However, you could use a dictionary instead of properties. You could also use operator_lookup to use the same syntax as properties. One problem with using a dictionary though, is that you lose any compile time validation.
You could use Introspection to loop through all the properties and assign the value when you find the one you’re looking for:
Dim props() As Introspection.PropertyInfo
props = Introspection.GetType(TheObject).GetProperties()
For i As Integer = 0 To props.LastIndex
If props(i).Name = "theName" Then
props(i).Value(TheObject) = value
End If
Next i
I like both the dictionary and introspection ideas. I think I will give introspection a go since the app is lightweight and has cycles to spare. I have been meaning to play around with introspection anyway.
If that approach turns out to be too burdensome I’ll fall back to the dictionary approach.