How can I determine whether an object is of a class or not in the Dart language?
I'm looking to do something like the following:
if (someObject.class.toString() == "Num") {
...
}
And what is the returned value type? Will it have to be a String?
The mirror library has been up and down and seems to be subject to rapid change right now, as the one thing I did find simply did not work as shown.
By using the
is
andis!
operators, like this:From the documentation:
Using the Mirrors API (see this example):
Recently
Object
gotruntimeType
getter. So, now we may not only compare type of object with another type, but actually get the class name of an object. As in:Furthermore, in the current version of Dart, you can now skip
toString
operation and directly compareruntimeType
of object with target type as inor