isAssignableFrom static method

bool isAssignableFrom(
  1. ClassMirror tgt,
  2. ClassMirror src
)

Returns whether a source class is assignable to target class.

  • tgt - target class
  • src - source class

Implementation

static bool isAssignableFrom(ClassMirror tgt, ClassMirror src) {
  if (tgt.qualifiedName == src.qualifiedName)
    return true;
  if (isTopClass(src)) //no more super class
    return false;

  //TypedefMirror does not implement superinterfaces/superclass
  if (src is TypedefMirror)
    return false;

  //check superinterfaces and superclass
  for (ClassMirror inf in src.superinterfaces)
    if (isAssignableFrom(tgt, inf))
      return true; //recursive

  return isAssignableFrom(tgt, src.superclass!); //recursive
}