diff --git a/framework-dotnet/src/lib/MBS.Core/Reflection/TypeExtensions.cs b/framework-dotnet/src/lib/MBS.Core/Reflection/TypeExtensions.cs new file mode 100644 index 0000000..b7930ed --- /dev/null +++ b/framework-dotnet/src/lib/MBS.Core/Reflection/TypeExtensions.cs @@ -0,0 +1,32 @@ +namespace MBS.Core.Reflection; + +public static class TypeExtensions +{ + public static bool IsSubclassOfGeneric(this Type toCheck, Type generic) + { + // thanks https://stackoverflow.com/a/457708 + + while (toCheck != null && toCheck != typeof(object)) + { + var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; + if (generic == cur) + { + return true; + } + + Type[] intfs = toCheck.GetInterfaces(); + foreach (Type intf in intfs) + { + // !!! HACK HACK HACK !!! + bool hack = intf.Namespace.Equals(generic.Namespace) && intf.Name.Equals(generic.Name); + if (hack) + { + return true; + } + } + toCheck = toCheck.BaseType; + } + return false; + } + +} \ No newline at end of file