System.Xml.Schema.SchemaCollectionCompiler.CannonicalizeChoice C# (CSharp) Method

CannonicalizeChoice() private method

private CannonicalizeChoice ( XmlSchemaChoice choice, bool root, bool substitution ) : XmlSchemaParticle
choice XmlSchemaChoice
root bool
substitution bool
return XmlSchemaParticle
        private XmlSchemaParticle CannonicalizeChoice(XmlSchemaChoice choice, bool root, bool substitution) {
            XmlSchemaChoice oldChoice = choice;
            if (choice.Items.Count > 0) {
                XmlSchemaChoice newChoice = new XmlSchemaChoice();
                newChoice.MinOccurs = choice.MinOccurs;
                newChoice.MaxOccurs = choice.MaxOccurs;
                foreach (XmlSchemaParticle p in choice.Items) {
                    XmlSchemaParticle p1 = CannonicalizeParticle(p, false, substitution);
                    if (p1 != XmlSchemaParticle.Empty) {
                        if (p1.MinOccurs == decimal.One && p1.MaxOccurs == decimal.One && p1 is XmlSchemaChoice) {
                            foreach (XmlSchemaParticle p2 in ((XmlSchemaChoice)p1).Items) {
                                newChoice.Items.Add(p2);
                            }
                        }
                        else {
                            newChoice.Items.Add(p1);
                        }
                    }
                }
                choice = newChoice;
            }
            if (!root && choice.Items.Count == 0) {
                if (choice.MinOccurs != decimal.Zero) {
                    SendValidationEvent(Res.Sch_EmptyChoice, oldChoice, XmlSeverityType.Warning);
                }
                return XmlSchemaParticle.Empty;
            }
            else if (!root && choice.Items.Count == 1 && choice.MinOccurs == decimal.One && choice.MaxOccurs == decimal.One) {
                return (XmlSchemaParticle)choice.Items[0];
            }
            else {
                return choice;
            }
        }