File tree Expand file tree Collapse file tree
GameFrameX.Foundation.Extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,30 @@ namespace GameFrameX.Foundation.Extensions;
1313/// </summary>
1414public static partial class TypeExtensions
1515{
16+ /// <summary>
17+ /// 判断类型是否实现了指定的接口
18+ /// </summary>
19+ /// <param name="targetType">要检查的类型,不能为null</param>
20+ /// <param name="interfaceType">目标接口类型,不能为null</param>
21+ /// <returns>
22+ /// 如果类型实现了指定的接口,则返回true;
23+ /// 否则返回false
24+ /// </returns>
25+ /// <remarks>
26+ /// 此方法会检查类型是否直接或间接地实现了指定的接口。
27+ /// 它会递归检查类型的继承链和接口实现。
28+ /// </remarks>
29+ /// <exception cref="ArgumentNullException">当<paramref name="targetType"/>或<paramref name="interfaceType"/>为null时抛出</exception>
30+ public static bool HasInterface ( Type targetType , Type interfaceType )
31+ {
32+ if ( targetType == null || interfaceType == null || ! interfaceType . IsInterface )
33+ {
34+ return false ;
35+ }
36+
37+ return interfaceType . IsAssignableFrom ( targetType ) ;
38+ }
39+
1640 /// <summary>
1741 /// 判断类型是否实现某个泛型接口或继承自某个泛型类
1842 /// </summary>
You can’t perform that action at this time.
0 commit comments