public IType GetMostGenericType(IType current, IType candidate)
{
if (null == current && null == candidate)
throw new ArgumentNullException("current", "Both 'current' and 'candidate' are null");
if (null == current)
return candidate;
if (null == candidate)
return current;
if (IsAssignableFrom(current, candidate))
return current;
if (IsAssignableFrom(candidate, current))
return candidate;
if (IsNumberOrBool(current) && IsNumberOrBool(candidate))
return GetPromotedNumberType(current, candidate);
if (IsCallableType(current) && IsCallableType(candidate))
return ICallableType;
if (current.IsClass && candidate.IsClass)
{
if (current == ObjectType || candidate == ObjectType)
return ObjectType;
if (current.GetTypeDepth() < candidate.GetTypeDepth())
return GetMostGenericType(current.BaseType, candidate);
return GetMostGenericType(current, candidate.BaseType);
}
return ObjectType;
}