gpt4 book ai didi

java - 在 Dart 中,有没有办法拦截对编程结构的访问和更改?

转载 作者:搜寻专家 更新时间:2023-11-01 02:45:34 24 4
gpt4 key购买 nike

例如,Java 的 Spring AOP 框架提供了一个拦截器来拦截某些进程的功能,例如,当一个方法执行时 - Spring AOP 可以劫持正在执行的方法,并在方法执行之前或之后添加额外的功能.

想知道Dart中有没有类似的东西。例如,您可以在 Dart 中拦截对变量的访问和更改吗?我无法在 Dart 文档中找到类似内容。

谢谢

最佳答案

目前您不能在运行时 执行此操作。一旦mirror builders 落地,您也许可以做这样的事情。来自 Reflection in Dart with Mirrors: An Introduction

We’d like to support more powerful reflective features in the future. These would include mirror builders, designed to allow programs to extend and modify themselves, and a mirror-based debugging API as well.

但是,您可以在预处理器(如 build.dart)中或使用 pub transformer构建时 执行此操作.您还使用 analyzer package如果需要,可以获取 AST。这可以看作是 Java 中的 APT。

关于java - 在 Dart 中,有没有办法拦截对编程结构的访问和更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23003498/

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