Search code examples
dartdart-mirrorsredstone.dart

Get classes that have fields annotated with Redstone's @Field()


I have some Dart classes in my project where I annotate some fields with Redstone Mapper's @Field() annotation.

How can I get all these classes at runtime?

I've seen the private Map _cache in redstone_mapper_factory... but it's private.

I'm aware of that I can use the Reflection package to scan these classes myself, however all of them are already being detected and stored by the Redstone mapper so I'd like to leverage that.


Solution

  • You can use dart:mirror to do that.

    But I don't think it's possible to get that by redstone, you should probably ask on github, even do the change yourself if you want and do a pull request, it should not be difficult, it is just a getter on _cache.

    https://github.com/redstone-dart/redstone_mapper