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

CannonicalizeChoice() private method

private CannonicalizeChoice ( XmlSchemaChoice choice, bool root ) : XmlSchemaParticle
choice XmlSchemaChoice
root bool
return XmlSchemaParticle
        private XmlSchemaParticle CannonicalizeChoice(XmlSchemaChoice choice, bool root) {
            XmlSchemaChoice oldChoice = choice;
            if (choice.Items.Count > 0) {
                XmlSchemaChoice newChoice = new XmlSchemaChoice();
                newChoice.MinOccurs = choice.MinOccurs;
                newChoice.MaxOccurs = choice.MaxOccurs;
                CopyPosition(newChoice, choice, true);
                foreach (XmlSchemaParticle p in choice.Items) {
                    XmlSchemaParticle p1 = CannonicalizeParticle(p, false);
                    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;
            }
        }
Compiler