public override bool IsAssignableFrom([NotNullWhen(true)] Type?c)
{
if (c is null)
{
return(false);
}
if (ReferenceEquals(c, this))
{
return(true);
}
// For runtime type, let the VM decide.
if (c.UnderlyingSystemType is RuntimeType fromType)
{
// both this and c (or their underlying system types) are runtime types
return(RuntimeTypeHandle.CanCastTo(fromType, this));
}
// Special case for TypeBuilder to be backward-compatible.
if (c is System.Reflection.Emit.TypeBuilder)
{
// If c is a subclass of this class, then c can be cast to this type.
if (c.IsSubclassOf(this))
{
return(true);
}
if (IsInterface)
{
return(c.ImplementInterface(this));
}
else if (IsGenericParameter)
{
Type[] constraints = GetGenericParameterConstraints();
for (int i = 0; i < constraints.Length; i++)
{
if (!constraints[i].IsAssignableFrom(c))
{
return(false);
}
}
return(true);
}
}
// For anything else we return false.
return(false);
}