将符号转换为字符串
问题描述:
有没有办法将符号转换为字符串?
Is there a way to covert a Symbol into a String?
例如,VariableMirror返回Symbols而不是字符串。有没有办法将一个Symbol转换成一个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?
答
import 'dart:mirrors';
void main() {
var sym = new Symbol('test');
print(MirrorSystem.getName(sym));
}
此输出:
This outputs:
test