internal static bool IsOrInheritsFrom(Type Derived, Type Base) { if (Derived == Base) { return(true); } if (Derived.IsGenericParameter) { if (Symbols.IsClass(Base) && (uint)(Derived.GenericParameterAttributes & GenericParameterAttributes.NotNullableValueTypeConstraint) > 0U && Symbols.IsOrInheritsFrom(typeof(ValueType), Base)) { return(true); } Type[] parameterConstraints = Derived.GetGenericParameterConstraints(); int index = 0; while (index < parameterConstraints.Length) { if (Symbols.IsOrInheritsFrom(parameterConstraints[index], Base)) { return(true); } checked { ++index; } } } else if (Symbols.IsInterface(Derived)) { if (Symbols.IsInterface(Base)) { Type[] interfaces = Derived.GetInterfaces(); int index = 0; while (index < interfaces.Length) { if (interfaces[index] == Base) { return(true); } checked { ++index; } } } } else if (Symbols.IsClass(Base) && Symbols.IsClassOrValueType(Derived)) { return(Derived.IsSubclassOf(Base)); } return(false); }