Hiya!
I am having some trouble figuring out how to use reflection in a
specific way and was wondering if anyone could help. I hope that I can
explain what I am trying to do clearly so bear with me. I am trying to
teach myself .net as a hobby so is what I am doing isn't the correct way
to do it please let me know. My curiosity would still like to know how
to go about it in the way that I am thinking or I could end up in the
nut-house.
Ok here it is.
Lets say that I have 10 different classes based on an interface. Within
those classes is the possibillity of one or more of its members to be of
the type of any other of the classes.
So far I have something like;
ISomeInterface
SpecificMethod as boolean
End Interface
SomeClass1
Implements ISomeInterface
Member1 as string
Member2 as Integer
Member3 as SomeClass5
SpecificMethod as boolean _
Implements ISomeInterface.SpecificMathod
End Class
SomeClass2...
SomeClass3...
SomeClass4...
SomeClass5
Implements ISomeInterface
Member11 as string
Member21 as Integer
Member31 as SomeClass10
SpecificMethod as boolean _
Implements ISomeInterface.SpecificMathod
End Class
SomeClass6...
SomeClass7...
SomeClass8...
SomeClass9...
SomeClass10
Implements ISomeInterface
Member12 as string
Member22 as Integer
Member32 as SomeClass3
SpecificMethod as boolean _
Implements ISomeInterface.SpecificMathod
End Class
Ok, hope I haven't lost ya yet. So now I have an object (or
whatever it should be called) that is a jumble of my classes. Say
something like;
MyCluster as New MyClass1
with all the sub-class objects created and added and what not.
Now that I have this, how could I recurse through those classes and\or
members based on my interface and run the SpecificMethod for each?
Something like;
SubOrFuntion RunThis(input as ISomeInterface)
Debug.Writeline(input.SpecificMethod.ToString)
For each Thingy in input
If Thingy is somehow compared to ISomeInterface Then
RunThis(Thingy)
End If
Next Thingy
End SubOrFunction
Whew, my brain hurts just thinking about it. I tried using GetType on
Thingy as well as some other thing that I have found on msdn but I
haven't been able to get the results that I am looking for.
Thanks for any help that you can offer.
Jason