Victor Savkin Victor Savkin - 6 months ago 69
Dart Question

Converting a Symbol into a String

Is there a way to covert a Symbol into a String?

For instance, a VariableMirror returns Symbols instead of Strings. Is there a way to convert a Symbol into a String, so I can print all the variable names of a class?

Answer Source

Use MirrorSystem.getName():

import 'dart:mirrors';

void main() {
  var sym = new Symbol('test');
  print(MirrorSystem.getName(sym));
}

This outputs:

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