gpt4 book ai didi

dart - 如何使用 Dart 和 Smoke 获取实例的参数化类型?

转载 作者:行者123 更新时间:2023-12-01 06:08:59 25 4
gpt4 key购买 nike

考虑这段代码:

class Foo {
List<String> listOfStrings;
}

使用 smoke包,如何通过查看 listOfStrings 获取 String

我看到我们可以从 Type 得到一个 Declaration,但我不知道如何从 Declaration 得到参数化类型.

这对于构建序列化库等非常重要。

最佳答案

目前不可能在烟雾中做到这一点。

甚至可能无法直接使用镜像 API。例如:

import 'dart:mirrors';
class B<T> {}
class A {
static B<int> b = new B<int>();
}
main() {
var x = reflectType(A);
print(x);
print(x.declarations[#b].type);
}

将打印 B , 但不是 B<int> .

关于dart - 如何使用 Dart 和 Smoke 获取实例的参数化类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25371826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com