Feat/array extensions 2d helper methods #150
Merged
Merged
Conversation
- 实现 IsInBounds 扩展方法用于检查二维数组坐标边界 - 提供泛型支持以适配不同类型的二维数组 - 包含完整的 XML 文档注释说明方法用途和参数 - 遵循 Apache 2.0 开源协议规范添加版权头文件
- 添加 GetOrDefault 方法用于获取越界时返回默认值的元素 - 添加 GetOr 方法用于获取越界时返回指定回退值的元素 - 添加 TryGet 方法用于尝试获取指定位置的元素 - 添加 GetNeighbors4 方法用于获取四个方向的邻居坐标 - 添加 GetNeighbors8 方法用于获取八个方向的邻居坐标 - 添加 Enumerate 方法用于枚举数组中所有元素及坐标 - 添加 Width 和 Height 方法分别获取数组宽高维度 - 在文件头注释中修复版权年份格式问题
审阅者指南新增 新增 ArrayExtensions 二维辅助方法的类图classDiagram
class ArrayExtensions {
<<static>>
+bool IsInBounds_T_(T[,] array, int x, int y)
+T GetOrDefault_T_(T[,] array, int x, int y)
+T GetOr_T_(T[,] array, int x, int y, T fallback)
+bool TryGet_T_(T[,] array, int x, int y, out T value)
+IEnumerable_ValueTuple_int_int_ GetNeighbors4_T_(T[,] array, int x, int y)
+IEnumerable_ValueTuple_int_int_ GetNeighbors8_T_(T[,] array, int x, int y)
+IEnumerable_ValueTuple_int_int_T_ Enumerate_T_(T[,] array)
+int Width_T_(T[,] array)
+int Height_T_(T[,] array)
}
class T
class GFramework_Core_Extensions
ArrayExtensions <.. T
文件级更改
技巧与命令与 Sourcery 交互
自定义你的体验访问你的 控制面板 可以:
获取帮助Original review guide in EnglishReviewer's GuideAdds a new ArrayExtensions utility class providing common 2D array helpers, including bounds checking, safe element access, neighbor enumeration, full enumeration, and dimension accessors for T[,] arrays. Class diagram for new ArrayExtensions 2D helpersclassDiagram
class ArrayExtensions {
<<static>>
+bool IsInBounds_T_(T[,] array, int x, int y)
+T GetOrDefault_T_(T[,] array, int x, int y)
+T GetOr_T_(T[,] array, int x, int y, T fallback)
+bool TryGet_T_(T[,] array, int x, int y, out T value)
+IEnumerable_ValueTuple_int_int_ GetNeighbors4_T_(T[,] array, int x, int y)
+IEnumerable_ValueTuple_int_int_ GetNeighbors8_T_(T[,] array, int x, int y)
+IEnumerable_ValueTuple_int_int_T_ Enumerate_T_(T[,] array)
+int Width_T_(T[,] array)
+int Height_T_(T[,] array)
}
class T
class GFramework_Core_Extensions
ArrayExtensions <.. T
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
|
Overall Grade |
Security Reliability Complexity Hygiene |
Code Review Summary
| Analyzer | Status | Updated (UTC) | Details |
|---|---|---|---|
| C# | Mar 30, 2026 12:18a.m. | Review ↗ | |
| Secrets | Mar 30, 2026 12:18a.m. | Review ↗ |
There was a problem hiding this comment.
Hey - 我在这里给出一些高层次的反馈:
- 在
IsInBounds和Enumerate循环中,你多次调用GetLength(0/1);建议将这些长度缓存在局部变量中,以避免在紧凑循环中重复进行边界元数据查找。 TryGet在越界时会将default!赋值给value;如果你预期会使用引用类型或可为空的值类型,可能需要使用可空性特性来标注这个 out 参数,或者明确在文档中说明,当失败时value会是default(T),以提升可读性和清晰度。
给 AI Agent 的提示词
Please address the comments from this code review:
## Overall Comments
- In `IsInBounds` and the `Enumerate` loops you repeatedly call `GetLength(0/1)`; consider caching these lengths in local variables to avoid redundant bounds metadata lookups in tight loops.
- `TryGet` assigns `default!` to `value` when out of bounds; if you expect reference types or nullable value types, you might want to annotate the out parameter with nullable attributes or explicitly document that `value` will be `default(T)` on failure for clarity.帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈来改进后续的代码审查。
Original comment in English
Hey - I've left some high level feedback:
- In
IsInBoundsand theEnumerateloops you repeatedly callGetLength(0/1); consider caching these lengths in local variables to avoid redundant bounds metadata lookups in tight loops. TryGetassignsdefault!tovaluewhen out of bounds; if you expect reference types or nullable value types, you might want to annotate the out parameter with nullable attributes or explicitly document thatvaluewill bedefault(T)on failure for clarity.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `IsInBounds` and the `Enumerate` loops you repeatedly call `GetLength(0/1)`; consider caching these lengths in local variables to avoid redundant bounds metadata lookups in tight loops.
- `TryGet` assigns `default!` to `value` when out of bounds; if you expect reference types or nullable value types, you might want to annotate the out parameter with nullable attributes or explicitly document that `value` will be `default(T)` on failure for clarity.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 在 IsInBounds 和 Enumerate 方法中缓存数组维度长度,避免重复读取元数据 - 为 TryGet 方法添加 MaybeNullWhen 特性注解以改善空值检查 - 更新 TryGet 方法文档说明其在失败时返回默认值的行为 - 新增 ArrayExtensionsTests 类,包含 TryGet 和 Enumerate 方法的完整测试用例 - 添加 using System.Diagnostics.CodeAnalysis 引入空值相关特性支持
This was referenced Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary by Sourcery
为二维数组添加用于边界检查、安全访问、邻居发现、枚举和尺寸查询的辅助扩展方法。
新特性:
IsInBounds扩展方法,用于验证二维数组中的坐标是否合法。TryGet模式。Width和Height)。Original summary in English
Summary by Sourcery
Add 2D array helper extensions for bounds checking, safe access, neighbor discovery, enumeration, and size queries.
New Features: