我有测试应用程序:
import 'dart:mirrors';
class A {
void eventHandlerInt(List<int> x){}
void eventHandlerBool(List<bool> x){}
}
void testMirrors(aFunction){
ClosureMirror mir = reflect(aFunction);
var param = mir.function.parameters.first;
//How to get the Type T of List<T> of the first param?
}
void main() {
var a = new A();
testMirrors(a.eventHandlerInt);
testMirrors(a.eventHandlerBool);
}
我希望能够找出泛型类型是传递到方法的第一个参数是什么testMirrors
,所以在上面的例子中是int
那么bool
。这有可能吗?如果我检查参数,则type属性为null。
List<TypeMirror> types = mir.function.parameters.first.type.typeArguments;
param.forEach((e) => print(e.simpleName));
版画
Symbol(“ int”)
Symbol(“ bool”)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句