public bool IsAssignableFrom(Type type)
{
// Special hack for handling the merged numeric types
if (type == typeof (Number))
{
if (this == typeof (int) || this == typeof (float) || this == typeof (long) ||
this == typeof (byte) || this == typeof (sbyte) || this == typeof (short) ||
this == typeof (ushort) || this == typeof (uint) || this == typeof (ulong) ||
this == typeof (double))
{
return true;
}
}
// Special hack to allow arbitrary delegates to be force cast into particular delegate
// if (type == typeof (Delegate) && type.IsAssignableFrom(this))
// {
// return true;
// }
// Check base type hierarchy
var current = type;
while (current != null)
{
if (current == this)
return true;
current = current.BaseType;
}
// Now check interfaces
for (var i = 0; i < type.GetInterfaceCount(); i++)
{
var item = type.GetInterface(i);
if (item == this)
return true;
}
return false;
}