attributes - 我可以轻松修改Dart库中的类吗?

标签 attributes dart

我正在使用寻路库,但我通常想知道的不只是针对这种情况。
它提供了一个类Grid,该类使用类Node来保存基本信息。 Node的文档说:

[...] and custom attributes may be added, depending on the algorithms' needs.

有没有一种方法可以定义Node的属性(例如steppedOnXTimes)?更具体地说,我想将属性添加到原始Node类或覆盖它,仅仅扩展它是不够的,因为Grid仍将使用原始Node类。

最佳答案

没有办法做到这一点。 pathfinding library是从JavaScript version移植而来的,我想文档并未进行更新以反射(reflect)这一点。

对于您的情况,您可能要做的最好是扩展grid.dart并提供_buildNodes的自定义构造函数和实现,该构造函数和实现使用您自己的Node类来扩展提供的Node类。

我知道没有通用的解决方案。

关于attributes - 我可以轻松修改Dart库中的类吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20921717/

相关文章:

javascript - 将 id 添加到可见元素的子元素

firebase - "NoSuchMethodError: tried to call a non-function, such as null: ' dart.global.firebase.auth '"在 flutter for web 中初始化 auth() 时

java.lang.NullPointerException : Attempt to invoke virtual method 'android. content.pm.PackageManager

flutter - 滚动 future 的 ListView

Dart 多个上限

Magento - 创建新的客户属性

css - 为 Wordpress OneAll 社交登录插件自定义 iframe

c# - 在 ASP.NET MVC 中使用属性实现对象级安全性

javascript - 如何在每个类中找到 href 属性?

file - dart 中的 lib/src 和/bin 有什么区别?