How to get the value from metadata, in Dart?

2019-07-28 10:26发布

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条回答
叼着烟拽天下
2楼-- · 2019-07-28 10:48

You can use InstanceMirror.getField :

metadata.getField(#name);
查看更多
登录 后发表回答