说我有以下注释和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端(服务器):
AndImNotPickedUpOnServer_IDoOnWebClient
中仅提供appModel.annotatedClasses
。在网络方面,两个类都给出了。
长话短说,我如何像上面的示例
const constructor
(对于CmdApp和Web一样)检索直接@AppModel(' :( ')
调用注释的类? 最佳答案
因为版本0.5.4
可反射类不支持带参数的构造函数
这出现在reflectable documentation中:
一种可能的解决方案是使用第二个注释来处理名称,例如:
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