call method of Property via introspection?

Dim myProperties() as Introspection.PropertyInfo = Introspection.GetType(self).GetProperties For i as Integer=0 to Ubound(myProperties) // if Property isa myClass then call method myMethod next

How do I call a method of myClass on each of the properties of ‘self’ if the property isa myClass?

here’s one way

dim v As Variant = myProperties(i).Value(self) //get the value if v IsA myClass then //test for type myClass(v).myMethod //cast and call end

I’ll give it a try… but what is the Invoke method of MethodInfo for?
The example in the help file isn’t very helpful.

MethodInfo represents a method and .Invoke will call that method. PropertyInfo represents a property and .Value returns or sets the actual property. In your situation, once you get the value out of PropertyInfo it’s a regular reference and you don’t need to deal with Introspection to handle it.

My use of Variant might be throwing you. That’s so it can grab any type of property without error and then test for type afterwards. You could also query the PropertyInfo for its type before accessing .Value. I think like this

if myProperties(i).PropertyType.FullName = "myClass" then dim c As myClass = myProperties(i).Value(self) if c <> nil then c.myMethod end

Maybe FullName should be just Name, and you’ll need to test for nil. In the previous version if the Variant is nil it won’t pass the IsA test.