This commit is contained in:
龙腾猫跃 committed 2026-07-01 07:17:49 +08:00
1 parent c18fef7074
commit 1f91e757c2
1 file changed
+3 -3
+15
View File
@@ -0,0 +1,15 @@
namespace MeloongCore;
public static class GeneralUtils {
/// <summary>
/// 判断对象是否为指定泛型类型的实例。
/// </summary>
public static bool IsGenericInstanceOf(object? instance, Type genericTypeDefinition) {
if (instance is null) return false;
for (var type = instance.GetType(); type is not null; type = type.BaseType) {
if (type.IsGenericType && type.GetGenericTypeDefinition() == genericTypeDefinition) return true;
}
return false;
}
}