reflection - 使用 Reflectable 与 MirrorSystem.getName 等效的是什么?

标签 reflection dart dart-mirrors

在 dart:mirrors 包中,从符号获取字符串值的方法是:

MirrorSystem.getName(#MySymbol);

可反射包有等效的吗?

最佳答案

这可能是您想要的,但它不像 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 {}

关于reflection - 使用 Reflectable 与 MirrorSystem.getName 等效的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31862996/

相关文章:

kotlin - Kotlin-KType的KClass <*>

dart - 如何向 Dart 类添加 getter,并在其构造函数上使用命名参数?

flutter - 类型 'GeoPoint' 不是 flutter firestore 中类型 'String' 的子类型

CheckBox 值在 onChanged 回调中始终为真

dart - 获取所有具有注释的类的 ClassMirror 实例

c# - PropertyInfo.GetProperty 在不应返回 null 时返回

c# - 任何时候访问类属性(获取或设置)时执行的方法?

dart - 使用dart检索 setter/getter 值:镜面反射

dart - 在什么情况下,reflectClass(o.runtimeType) 会返回与reflect(o).type 不同的结果?

c# - 查找对象的所有属性和子属性