System.Xml.Schema.XmlSchemaType.IsDerivedFrom C# (CSharp) Méthode

IsDerivedFrom() public static méthode

public static IsDerivedFrom ( XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except ) : bool
derivedType XmlSchemaType
baseType XmlSchemaType
except XmlSchemaDerivationMethod
Résultat bool
        public static bool IsDerivedFrom(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except) {
            if (derivedType == null || baseType == null) {
                return false;
            }

            if (derivedType == baseType) {
                return true;
            }
            
            if (baseType == XmlSchemaComplexType.AnyType) { //Not checking for restriction blocked since all types are implicitly derived by restriction from xs:anyType
                return true;
            }
            do {
                XmlSchemaSimpleType dt = derivedType as XmlSchemaSimpleType;
                XmlSchemaSimpleType bt = baseType as XmlSchemaSimpleType;
                if (bt != null && dt != null) { //SimpleTypes
                    if (bt == DatatypeImplementation.AnySimpleType) { //Not checking block=restriction
                        return true;
                    }
                    if ((except & derivedType.DerivedBy) != 0 || !dt.Datatype.IsDerivedFrom(bt.Datatype)) {
                        return false;
                    }
                    return true;
                }
                else { //Complex types
                    if ((except & derivedType.DerivedBy) != 0) {
                        return false;
                    }
                    derivedType = derivedType.BaseXmlSchemaType;
                    if (derivedType == baseType) {
                        return true;
                    }
                }

            } while(derivedType != null);

            return false;
        }

Usage Example

 /// <summary>Returns a value indicating if the derived schema type specified is derived from the base schema type specified</summary>
 /// <returns>true if the derived type is derived from the base type; otherwise, false.</returns>
 /// <param name="derivedType">The derived <see cref="T:System.Xml.Schema.XmlSchemaType" /> to test.</param>
 /// <param name="baseType">The base <see cref="T:System.Xml.Schema.XmlSchemaType" /> to test the derived <see cref="T:System.Xml.Schema.XmlSchemaType" /> against.</param>
 /// <param name="except">One of the <see cref="T:System.Xml.Schema.XmlSchemaDerivationMethod" /> values representing a type derivation method to exclude from testing.</param>
 public static bool IsDerivedFrom(XmlSchemaType derivedType, XmlSchemaType baseType, XmlSchemaDerivationMethod except)
 {
     return(derivedType.BaseXmlSchemaType != null && (derivedType.DerivedBy & except) == XmlSchemaDerivationMethod.Empty && (derivedType.BaseXmlSchemaType == baseType || XmlSchemaType.IsDerivedFrom(derivedType.BaseXmlSchemaType, baseType, except)));
 }
All Usage Examples Of System.Xml.Schema.XmlSchemaType::IsDerivedFrom