How to get the value from metadata, in Dart?

女生的网名这么多〃 提交于 2019-12-11 12:11:58

问题


Dart code:

@Table("users")
class User {}

And the metadata declaration:

class Table {
    final String name;
    const Table(this.name);
}

I can get the metadata @Table by following code:

var classMirror = reflectClass(User);
var metadata = classMirror.metadata;
print(metadata);

Which prints:

[InstanceMirror on Instance of 'Table']

But I don't know how to get the users from it :(


回答1:


You can use InstanceMirror.getField :

metadata.getField(#name);


来源:https://stackoverflow.com/questions/21555598/how-to-get-the-value-from-metadata-in-dart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!