Ravi Teja Gudapati Ravi Teja Gudapati - 1 year ago 88
Dart Question

What are the use cases of multilevel Symbols?

Glossary: What I mean by multilevel Symbol is something that is like #Dummy.bar instead of single level like #bar. Dont know what is better name for it, sorry.

Symbols are very nifty. I can do:

class Foo {
static String hello() => "Said hello!";

ClassMirror clMir = reflectType(Foo) as ClassMirror();
print(clMir.invoke(#hello, []));

It prints Said hello!. Great!

But one cant do:

class Bar{
static final Bar bar = new Bar();

ClassMirror clMir = reflectType(Bar) as ClassMirror();
print(clMir.invoke(#bar.hello, []));

This would fail.

Also, I haven't found a place where you can get reflection for multilevel Symbol, like
and get InstanceMirror for bar or something similar.

So are there use cases for multilevel Symbols?

lrn lrn
Answer Source

There are different use-cases. Primarily, it represents a library name (library foo.bar.baz;). The mirror system uses it for that (see, e.g., https://api.dartlang.org/stable/1.20.1/dart-mirrors/MirrorSystem/findLibrary.html).

Secondarily, the mirror system is sometimes using it as a "qualified name" like library.name.ClassName.memberName to represent an exact class or library member (https://api.dartlang.org/stable/1.20.1/dart-mirrors/DeclarationMirror/qualifiedName.html).

It's not that useful outside of the mirror system.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download