Skip to content

Commit 10319a1

Browse files
committed
refactor(extensions): TypeExtensions 统一参数检查模式
使用 ArgumentNullException.ThrowIfNull 替代传统模式
1 parent 1b10ad9 commit 10319a1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

GameFrameX.Foundation.Extensions/TypeExtensions.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ public static partial class TypeExtensions
2929
/// 它会递归检查类型的继承链和接口实现。
3030
/// </remarks>
3131
/// <exception cref="ArgumentNullException">当<paramref name="targetType"/>或<paramref name="interfaceType"/>为null时抛出</exception>
32+
/// <exception cref="ArgumentException">当<paramref name="interfaceType"/>不是接口类型时抛出</exception>
3233
public static bool HasInterface(Type targetType, Type interfaceType)
3334
{
34-
if (targetType == null || interfaceType == null || !interfaceType.IsInterface)
35+
ArgumentNullException.ThrowIfNull(targetType, nameof(targetType));
36+
ArgumentNullException.ThrowIfNull(interfaceType, nameof(interfaceType));
37+
38+
if (!interfaceType.IsInterface)
3539
{
36-
return false;
40+
throw new ArgumentException(LocalizationService.GetString(LocalizationKeys.Exceptions.TargetTypeMustBeInterface), nameof(interfaceType));
3741
}
3842

3943
return interfaceType.IsAssignableFrom(targetType);

0 commit comments

Comments
 (0)