Worker 额外日志、迁移 IsGenericInstanceOf

This commit is contained in:
龙腾猫跃 committed 2026-06-28 23:34:24 +08:00
1 parent dbdbfcebd2
commit fe9fc04c20
3 files changed
+41 -11

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
namespace MeloongCore.Extensions;
public static class GeneralExtension {
/// <summary>
/// 判断对象是否为指定泛型类型的实例。
/// </summary>
public static bool IsGenericInstanceOf(this 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;
}
}