System.Xml.Schema.SchemaCollectionCompiler.CompileSimpleType C# (CSharp) Méthode

CompileSimpleType() private méthode

private CompileSimpleType ( XmlSchemaSimpleType simpleType ) : void
simpleType XmlSchemaSimpleType
Résultat void
        private void CompileSimpleType(XmlSchemaSimpleType simpleType) {
            if (simpleType.IsProcessing) {
                throw new XmlSchemaException(Res.Sch_TypeCircularRef, simpleType);
            }
            if (simpleType.ElementDecl != null) { // already compiled
                return;
            }
            simpleType.IsProcessing = true;
            try {
                if (simpleType.Content is XmlSchemaSimpleTypeList) {
                    XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)simpleType.Content;
                    XmlSchemaDatatype datatype;
                    simpleType.SetBaseSchemaType(DatatypeImplementation.AnySimpleType); 
                    if (list.ItemTypeName.IsEmpty) {
                        CompileSimpleType(list.ItemType);
                        list.BaseItemType = list.ItemType;
                        datatype = list.ItemType.Datatype;
                    }
                    else {
                        XmlSchemaSimpleType type = GetSimpleType(list.ItemTypeName);
                        if (type != null) {
                            if ((type.FinalResolved & XmlSchemaDerivationMethod.List) != 0) {
                                SendValidationEvent(Res.Sch_BaseFinalList, simpleType);
                            }
                            list.BaseItemType = type;
                            datatype = type.Datatype;
                        }
                        else {
                            throw new XmlSchemaException(Res.Sch_UndeclaredSimpleType, list.ItemTypeName.ToString(), simpleType);   
                        }
                    }
                    simpleType.SetDatatype(datatype.DeriveByList(simpleType));
                    simpleType.SetDerivedBy(XmlSchemaDerivationMethod.List);
                }
                else if (simpleType.Content is XmlSchemaSimpleTypeRestriction) {
                    XmlSchemaSimpleTypeRestriction restriction = (XmlSchemaSimpleTypeRestriction)simpleType.Content;
                    XmlSchemaDatatype datatype;
                    if (restriction.BaseTypeName.IsEmpty) {
                        CompileSimpleType(restriction.BaseType);
                        simpleType.SetBaseSchemaType(restriction.BaseType);
                        datatype = restriction.BaseType.Datatype;
                    }
                    else if (simpleType.Redefined != null && restriction.BaseTypeName == simpleType.Redefined.QualifiedName) {
                        CompileSimpleType((XmlSchemaSimpleType)simpleType.Redefined);
                        simpleType.SetBaseSchemaType(simpleType.Redefined.BaseXmlSchemaType);
                        datatype = simpleType.Redefined.Datatype;
                    }
                    else {
                        if (restriction.BaseTypeName.Equals(DatatypeImplementation.QnAnySimpleType)) {
                            throw new XmlSchemaException(Res.Sch_InvalidSimpleTypeRestriction, restriction.BaseTypeName.ToString(), simpleType);   
                        }
                        XmlSchemaSimpleType type = GetSimpleType(restriction.BaseTypeName);
                        if (type != null) {
                            if ((type.FinalResolved & XmlSchemaDerivationMethod.Restriction) != 0) {
                                SendValidationEvent(Res.Sch_BaseFinalRestriction, simpleType);
                            }
                            simpleType.SetBaseSchemaType(type);
                            datatype = type.Datatype;
                        }
                        else {
                            throw new XmlSchemaException(Res.Sch_UndeclaredSimpleType, restriction.BaseTypeName.ToString(), simpleType);   
                        }
                    }
                    simpleType.SetDatatype(datatype.DeriveByRestriction(restriction.Facets, NameTable, simpleType));
                    simpleType.SetDerivedBy(XmlSchemaDerivationMethod.Restriction);
                }
                else { //simpleType.Content is XmlSchemaSimpleTypeUnion
                    XmlSchemaSimpleType[] baseTypes = CompileBaseMemberTypes(simpleType);
                    simpleType.SetBaseSchemaType(DatatypeImplementation.AnySimpleType);
                    simpleType.SetDatatype(XmlSchemaDatatype.DeriveByUnion(baseTypes, simpleType));
                    simpleType.SetDerivedBy(XmlSchemaDerivationMethod.Union);
                }
            } 
            catch (XmlSchemaException e) {
                if (e.SourceSchemaObject == null) {
                    e.SetSource(simpleType);
                }
                SendValidationEvent(e);
                simpleType.SetDatatype(DatatypeImplementation.AnySimpleType.Datatype);
            } 
            finally {
                SchemaElementDecl decl = new SchemaElementDecl();
                decl.ContentValidator = ContentValidator.TextOnly;
                decl.SchemaType = simpleType;
                decl.Datatype = simpleType.Datatype;
                simpleType.ElementDecl = decl;
                simpleType.IsProcessing = false;
            }
        }