1

我有测试应用程序:

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。这甚至可能吗?如果我检查参数类型属性为空。

4

1 回答 1

4
List<TypeMirror> types = mir.function.parameters.first.type.typeArguments;
param.forEach((e) => print(e.simpleName));

印刷

符号(“int”)
符号(“布尔”)

于 2014-05-19T17:55:36.903 回答