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

CannonicalizeAll() private method

private CannonicalizeAll ( XmlSchemaAll all, bool root, bool substitution ) : XmlSchemaParticle
all XmlSchemaAll
root bool
substitution bool
return XmlSchemaParticle
        private XmlSchemaParticle CannonicalizeAll(XmlSchemaAll all, bool root, bool substitution) {
            if (all.Items.Count > 0) {
                XmlSchemaAll newAll = new XmlSchemaAll();
                newAll.MinOccurs = all.MinOccurs;
                newAll.MaxOccurs = all.MaxOccurs;
                newAll.SourceUri = all.SourceUri; // all is the only one that might need and error message
                newAll.LineNumber = all.LineNumber;
                newAll.LinePosition = all.LinePosition;
                foreach (XmlSchemaElement e in all.Items) {
                    XmlSchemaParticle p = CannonicalizeParticle(e, false, substitution);
                    if (p != XmlSchemaParticle.Empty) {
                        newAll.Items.Add(p);
                    }
                }
                all = newAll;
            }
            if (all.Items.Count == 0) {
                return XmlSchemaParticle.Empty;
            }
            else if (root && all.Items.Count == 1) {
                XmlSchemaSequence newSequence = new XmlSchemaSequence();
                newSequence.MinOccurs = all.MinOccurs;
                newSequence.MaxOccurs = all.MaxOccurs;
                newSequence.Items.Add((XmlSchemaParticle)all.Items[0]);
                return newSequence;
            }
            else if (!root && all.Items.Count == 1 && all.MinOccurs == decimal.One && all.MaxOccurs == decimal.One) {
                return (XmlSchemaParticle)all.Items[0];
            }
            else if (!root) {
                SendValidationEvent(Res.Sch_NotAllAlone, all);
                return XmlSchemaParticle.Empty;
            }
            else {
                return all;
            }
        }