How to check an object implements an interface?

I’m trying to research how to use dynamic global channels. Let’s ignore the fact that there is only one interface and assume that there could be other objects. Now I have a simple hierarchy with “apple” and “peach” implementing the “fruit” interface and a global channel of type Object.


изображение

C# has simple notation for type comparison

изображение

.
Is there anything useful to find in the Node Browser in this case?

Still the most wanted fuzzy search feature in Node Browser
I insist that the search be brought back a la Beta.

InterfacesAndClasses.vl (24.8 KB)

In my research, I’ve even reached an exception
Hit one of the regions and try to save by ctrl+S
stable gamma 5.2

upd: False alarm, it happens when I append files to the forum. Can this be avoided?

InterfacesAndClasses.vl (24.8 KB)

In general, satisfactory results can be obtained with TypeSwitch. Am I doing it right?

InterfacesAndClassesTypeSwitch.vl (27.1 KB)

You could use cast as:

4 Likes

Fruit interface Example.vl (18.7 KB)

2 Likes

Kind of bump

The same question again, but this time a bit more serious. Suppose I have a large number of objects in a spread that implement multiple interfaces (and one common to the whole spread).

Spread has objects with different implemented interfaces. how can I filter them by interface type?

VegsFilter.vl (18.0 KB)

Can you try to CastAs and check if it succeeds?

You are right, it’s works

изображение

Is it efficient?

Isn’t this what OfType does?

Yes, use OfType

2 Likes

@readme @Elias @sebescudie Thank you!

image

A small question on the topic.
If there is a sequences of objects, for some reason the tooltip doesn’t work. But it works if it is a spread. What could it be?

Or do you suggest converting the sequence?

изображение

The tooltip doesn’t show you anything because in case of a sequence it could trigger unwanted side-effects. As an extreme example, we could come up with a sequence which when iterated asks a server on the other side of the world for its next item. Now imagine that it takes a very long time to get a response from the server, it would definitely not be a good idea to trigger it from the tooltip just because you hovered a pin.

What we could do is add some sort of user interaction to the toolip which would trigger the iteration when pressing a button. Will write it up as a feature request since it’s not the first time this comes up.

2 Likes