可反射:myAnnotation.annotatedClasses 不同的结果 CmdApp<>Client

Reflectable: myAnnotation.annotatedClasses different result CmdApp<>Client

假设我有以下注释和 2 类:

class AppModel extends Reflectable {
  final String name;
  const AppModel([this.name])
      : super(newInstanceCapability, metadataCapability);
}

const appModel = const AppModel();

@appModel
class ImGonnaBePickedUp {

}

@AppModel(' :( ')
class AndImNotPickedUpOnServer_IDoOnWebClient {

}

main() {
  appModel.annotatedClasses // that's what I mean by "Picked Up".
}

在 CmdApp 端(服务器):appModel.annotatedClasses 中仅给出 AndImNotPickedUpOnServer_IDoOnWebClient

网页端,类都给出了。

长话短说,我如何检索像上面的示例 @AppModel(' :( ') 那样用直接 const constructor 调用注释的 类(对于 CmdApp 和 Web)?

因为版本 0.5.4 可反射 类 不支持带参数的构造函数

这出现在 reflectable documentation:

Footnotes: 1. Currently, the only setup which is supported is when the metadata object is an instance of a direct subclass of the class [Reflectable], say MyReflectable, and that subclass defines a const constructor taking zero arguments. This ensures that every subclass of Reflectable used as metadata is a singleton class, which means that the behavior of the instance can be expressed by generating code in the class. Generalizations of this setup may be supported in the future if compelling use cases come up.

一个可能的解决方案是使用第二个注释来处理名称,例如:

import 'package:reflectable/reflectable.dart';
import 'package:drails_commons/drails_commons.dart';

class AppModel extends Reflectable {
  const AppModel()
      : super(newInstanceCapability, metadataCapability);
}

const appModel = const AppModel();

class TableName {

  final String name;

  const TableName(this.name);

}

@appModel
class ImGonnaBePickedUp {

}

@appModel
@TableName(' :( ')
class AndImNotPickedUpOnServer_WorksOnWebClient {

}

main() {
  print(appModel.annotatedClasses); // that's what I mean by "Picked Up".

  print(new GetValueOfAnnotation<TableName>()
      .fromDeclaration(appModel.reflectType(AndImNotPickedUpOnServer_WorksOnWebClient)).name);
}

注意:我也在使用 drails_common package