From 6908c74efc7c43616d101cf6d23c36efa4a6b6cf Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sun, 29 Mar 2026 22:04:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(extensions):=20=E6=B7=BB=E5=8A=A0=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E6=89=A9=E5=B1=95=E6=96=B9=E6=B3=95=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E4=BA=8C=E7=BB=B4=E6=95=B0=E7=BB=84=E8=BE=B9=E7=95=8C=E6=A3=80?= =?UTF-8?q?=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现 IsInBounds 扩展方法用于检查二维数组坐标边界 - 提供泛型支持以适配不同类型的二维数组 - 包含完整的 XML 文档注释说明方法用途和参数 - 遵循 Apache 2.0 开源协议规范添加版权头文件 --- GFramework.Core/Extensions/ArrayExtensions.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 GFramework.Core/Extensions/ArrayExtensions.cs diff --git a/GFramework.Core/Extensions/ArrayExtensions.cs b/GFramework.Core/Extensions/ArrayExtensions.cs new file mode 100644 index 0000000..bc711f9 --- /dev/null +++ b/GFramework.Core/Extensions/ArrayExtensions.cs @@ -0,0 +1,35 @@ +// Copyright (c) 2026 GeWuYou +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +namespace GFramework.Core.Extensions; + +/// +/// 数组扩展方法类,提供二维数组的边界检查等实用功能。 +/// +public static class ArrayExtensions +{ + /// + /// 检查二维数组的给定坐标是否在有效边界内。 + /// + /// 数组元素类型。 + /// 要检查的二维数组。 + /// 要检查的 X 坐标(第一维索引)。 + /// 要检查的 Y 坐标(第二维索引)。 + /// 如果坐标在数组边界内则返回 true;否则返回 false。 + public static bool IsInBounds(this T[,] array, int x, int y) + { + return x >= 0 && y >= 0 && + x < array.GetLength(0) && + y < array.GetLength(1); + } +} \ No newline at end of file