internal bool ValidateTypeDerivationOK(object baseType, ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            if (this == baseType || baseType == XmlSchemaSimpleType.AnySimpleType || baseType == XmlSchemaComplexType.AnyType)
            {
                return(true);
            }
            XmlSchemaSimpleType xmlSchemaSimpleType = baseType as XmlSchemaSimpleType;

            if (xmlSchemaSimpleType != null && (xmlSchemaSimpleType.FinalResolved & this.resolvedDerivedBy) != XmlSchemaDerivationMethod.Empty)
            {
                if (raiseError)
                {
                    base.error(h, "Specified derivation is prohibited by the base type.");
                }
                return(false);
            }
            if (base.BaseXmlSchemaType == baseType || base.Datatype == baseType)
            {
                return(true);
            }
            XmlSchemaSimpleType xmlSchemaSimpleType2 = base.BaseXmlSchemaType as XmlSchemaSimpleType;

            if (xmlSchemaSimpleType2 != null && xmlSchemaSimpleType2.ValidateTypeDerivationOK(baseType, h, schema, false))
            {
                return(true);
            }
            XmlSchemaDerivationMethod xmlSchemaDerivationMethod = this.Variety;

            if (xmlSchemaDerivationMethod == XmlSchemaDerivationMethod.List || xmlSchemaDerivationMethod == XmlSchemaDerivationMethod.Union)
            {
                if (baseType == XmlSchemaSimpleType.AnySimpleType)
                {
                    return(true);
                }
            }
            if (xmlSchemaSimpleType != null && xmlSchemaSimpleType.Variety == XmlSchemaDerivationMethod.Union)
            {
                foreach (object baseType2 in ((XmlSchemaSimpleTypeUnion)xmlSchemaSimpleType.Content).ValidatedTypes)
                {
                    if (this.ValidateTypeDerivationOK(baseType2, h, schema, false))
                    {
                        return(true);
                    }
                }
            }
            if (raiseError)
            {
                base.error(h, "Invalid simple type derivation was found.");
            }
            return(false);
        }
Exemplo n.º 2
0
        // 3.14.6 Type Derivation OK (Simple)
        internal bool ValidateTypeDerivationOK(object baseType,
                                               ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            // 1
            // Note that anyType should also be allowed as anySimpleType.
            if (this == baseType || baseType == XmlSchemaSimpleType.AnySimpleType ||
                baseType == XmlSchemaComplexType.AnyType)
            {
                return(true);
            }

            // 2.1
            XmlSchemaSimpleType baseSimpleType = baseType as XmlSchemaSimpleType;

            if (baseSimpleType != null &&
                (baseSimpleType.FinalResolved & resolvedDerivedBy) != 0)
            {
                if (raiseError)
                {
                    error(h, "Specified derivation is prohibited by the base type.");
                }
                return(false);
            }

            // 2.2.1
            if (BaseXmlSchemaType == baseType || Datatype == baseType)
            {
                return(true);
            }

            // 2.2.2
            XmlSchemaSimpleType thisBaseSimpleType = BaseXmlSchemaType as XmlSchemaSimpleType;

            if (thisBaseSimpleType != null)
            {
                if (thisBaseSimpleType.ValidateTypeDerivationOK(baseType, h, schema, false))
                {
                    return(true);
                }
            }

            // 2.2.3
            switch (Variety)
            {
            case XmlSchemaDerivationMethod.Union:
            case XmlSchemaDerivationMethod.List:
                if (baseType == XmlSchemaSimpleType.AnySimpleType)
                {
                    return(true);
                }
                break;
            }

            // 2.2.4 validly derived from one of the union member type.
            if (baseSimpleType != null && baseSimpleType.Variety == XmlSchemaDerivationMethod.Union)
            {
                foreach (object memberType in ((XmlSchemaSimpleTypeUnion)baseSimpleType.Content).ValidatedTypes)
                {
                    if (this.ValidateTypeDerivationOK(memberType, h, schema, false))
                    {
                        return(true);
                    }
                }
            }

            if (raiseError)
            {
                error(h, "Invalid simple type derivation was found.");
            }
            return(false);
        }