bool WeavePointHasLooseEnd(IWeavePoint weavePoint)
{
// Simple choice with explicit divert
// definitely doesn't have a loose end
if (weavePoint is Choice) {
var choice = (Choice)weavePoint;
// However, explicit gather point is definitely a loose end
if (choice.hasExplicitGather) {
return true;
}
if (choice.hasTerminatingDivert) {
return false;
}
}
// No content, and no simple divert above, must be a loose end.
// (content list on Choices gets created on demand, hence how
// it could be null)
if (weavePoint.content == null) {
return true;
}
// Detect a divert object within a weavePoint's main content
// Work backwards since we're really interested in the end,
// although it doesn't actually make a difference!
else {
for (int i = weavePoint.content.Count - 1; i >= 0; --i) {
var innerDivert = weavePoint.content [i] as Divert;
if (innerDivert && !innerDivert.isToGather) {
return false;
}
}
return true;
}
}