private bool GatherGroupChoices(XmlSchemaParticle particle, NameTable choiceElements, string identifier, string ns, ref bool needExplicitOrder, bool allowDuplicates)
{
if (particle is XmlSchemaGroupRef)
{
XmlSchemaGroupRef refGroup = (XmlSchemaGroupRef)particle;
if (!refGroup.RefName.IsEmpty)
{
AddReference(refGroup.RefName, GroupsInUse, SR.XmlCircularGroupReference);
if (GatherGroupChoices(FindGroup(refGroup.RefName), choiceElements, identifier, refGroup.RefName.Namespace, ref needExplicitOrder, allowDuplicates))
{
RemoveReference(refGroup.RefName, GroupsInUse);
return true;
}
RemoveReference(refGroup.RefName, GroupsInUse);
}
}
else if (particle is XmlSchemaGroupBase)
{
XmlSchemaGroupBase group = (XmlSchemaGroupBase)particle;
bool groupRepeats = group.IsMultipleOccurrence;
XmlSchemaAny any = null;
bool duplicateElements = false;
for (int i = 0; i < group.Items.Count; i++)
{
object item = group.Items[i];
if (item is XmlSchemaGroupBase || item is XmlSchemaGroupRef)
{
if (GatherGroupChoices((XmlSchemaParticle)item, choiceElements, identifier, ns, ref needExplicitOrder, allowDuplicates))
groupRepeats = true;
}
else if (item is XmlSchemaAny)
{
if (GenerateOrder)
{
AddScopeElements(choiceElements, ImportAny((XmlSchemaAny)item, true, ns), ref duplicateElements, allowDuplicates);
}
else
{
any = (XmlSchemaAny)item;
}
}
else if (item is XmlSchemaElement)
{
XmlSchemaElement element = (XmlSchemaElement)item;
XmlSchemaElement headElement = GetTopLevelElement(element);
if (headElement != null)
{
XmlSchemaElement[] elements = GetEquivalentElements(headElement);
for (int j = 0; j < elements.Length; j++)
{
if (elements[j].IsMultipleOccurrence) groupRepeats = true;
AddScopeElement(choiceElements, ImportElement(elements[j], identifier, typeof(TypeMapping), null, elements[j].QualifiedName.Namespace, true), ref duplicateElements, allowDuplicates);
}
}
if (element.IsMultipleOccurrence) groupRepeats = true;
AddScopeElement(choiceElements, ImportElement(element, identifier, typeof(TypeMapping), null, element.QualifiedName.Namespace, false), ref duplicateElements, allowDuplicates);
}
}
if (any != null)
{
AddScopeElements(choiceElements, ImportAny(any, true, ns), ref duplicateElements, allowDuplicates);
}
if (!groupRepeats && !(group is XmlSchemaChoice) && group.Items.Count > 1)
{
groupRepeats = true;
}
return groupRepeats;
}
return false;
}