add TypeExtensions to support Type.IsSubclassOfGeneric(...)
This commit is contained in:
parent
623402805b
commit
6ee1135732
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user