Pretty much as the title says. I have an object stored in an Auto that I need to determine if it implements an interface. Xojo.Introspection.TypeInfo.IsSubclassOf doesn’t help with this, as it checks for hierarchy, not interfaces.
I could simply try to assign the auto to a variable of the interface type I want and catch a type mismatch, but that seems like the wrong way to do it. Anybody have a better idea?
Of course it’s too obvious.
I’ve been habitually avoiding IsA because it either does or used to cause crashes with Auto under certain circumstances. Of course, I can’t find the feedback report about it now.
Well, it’s not a crash, but
Dim Arr() As Auto
Dim Instance As Auto = Arr
If Instance IsA TestInterface Then
MsgBox "Implements"
Else
MsgBox "Not Implements"
End If
Does cause a TypeMismatchException.
Right. Interfaces can’t be applied to an array. Your code:
If Instance IsA TestInterface Then
would also fail if you were testing against a class name. You’re not checking if the members of the array are of that type, you’re checking if the array itself is.
Of course, but my point is that it makes it really difficult to use. I can’t simply to If Value IsA Interface Then
because Value could be anything. So best I can tell, I still need to go back to introspection to make sure what is in that Auto isn’t an array before I test it.
Fwiw, the case you’re thinking of is:
<https://xojo.com/issue/39308>