Search code examples
reflectiondartdart-mirrors

What is the equivalent to MirrorSystem.getName using reflectable?


In the dart:mirrors package the way to get a string value from a symbol was:

MirrorSystem.getName(#MySymbol);

is there any equivalent for reflectable package?


Solution

  • This might be what you want but it's not as generic as MirrorSystem.getName(#MySymbol);

    library some_lib;
    
    //import 'dart:mirrors' as mirr;
    import 'package:reflectable/reflectable.dart';
    
    class Reflector extends Reflectable {
      const Reflector() : super(typeCapability);
    }
    
    const Reflector reflector = const Reflector();
    
    main() {
    //  print(mirr.MirrorSystem.getName(#SomeClass));
      reflector.libraries.values.forEach((LibraryMirror lm) {
        if (lm.declarations.containsKey('SomeClass')) {
          print(lm.declarations['SomeClass']);
        }
      });
    }
    
    @reflector
    class SomeClass {}