I have a class object “A” that I want to objectify/represent using target. I can accomplish this by the following code (visual basic):
dim target : target = A
Now, if the object A has a property, for example, a0, I can access this property by
target.a0
However, if now I have another class object B, and its property is b0 instead of a0, I have to manually access this property by changing the target first and then access its property as following:
dim target : target = B
target.b0
What I want to accomplish is to objectify the a0 and b0 using another target-like representation. If possible, this is similar to what I am going after:
dim target1 : target1 = A
dim target2 : target2 = a0
target1.target2
I know this doesn’t work, because VB didn’t really think target1 is a keyword like target. Could anyone provide a good solution?
Thanks.
Based on my understanding of what you’re trying to accomplish (which may be a bold assumption on my part), you can’t do what you’re trying to do. Assuming this is all VB.NET, the declaration of “Dim target2” is completely dissimilar from the reference to a property or method reference as you offer in “target1.target2”. In the latter instance, “.target2” has to be a property or method of the type of which target1 was declared. The direct declaration I think you’re trying to accomplish just isn’t the way the language is constructed.
You could probably pull off some syntax tricks to approach what this does, but in terms of making “target1.target2” resolve to a literal reference to “A.a0” in a declarative manner such as that just won’t work.
If I’ve misunderstood, I’ll offer apologies in advance.
Good luck!