public static bool IsBaseAggregate(AggregateSymbol derived, AggregateSymbol @base)
{
Debug.Assert(!derived.IsEnum() && [email protected]());
if (derived == @base)
{
return(true); // identity.
}
// refactoring error tolerance: structs and delegates can be base classes in error scenarios so
// we cannot filter on whether or not the base is marked as sealed.
if (@base.IsInterface())
{
// Search the direct and indirect interfaces via ifacesAll, going up the base chain...
while (derived != null)
{
foreach (AggregateType iface in derived.GetIfacesAll().Items)
{
if (iface.getAggregate() == @base)
{
return(true);
}
}
derived = derived.GetBaseAgg();
}
return(false);
}
// base is a class. Just go up the base class chain to look for it.
while (derived.GetBaseClass() != null)
{
derived = derived.GetBaseClass().getAggregate();
if (derived == @base)
{
return(true);
}
}
return(false);
}