System.Xml.Schema.DatatypeImplementation.IsDerivedFrom C# (CSharp) Method

IsDerivedFrom() public method

public IsDerivedFrom ( XmlSchemaDatatype datatype ) : bool
datatype XmlSchemaDatatype
return bool
        public override bool IsDerivedFrom(XmlSchemaDatatype datatype)
        {
            if (datatype == null)
            {
                return false;
            }

            //Common case - Derived by restriction
            for (DatatypeImplementation dt = this; dt != null; dt = dt._baseType)
            {
                if (dt == datatype)
                {
                    return true;
                }
            }
            if (((DatatypeImplementation)datatype)._baseType == null)
            { //Both are built-in types
                Type derivedType = this.GetType();
                Type baseType = datatype.GetType();
                return baseType == derivedType || derivedType.GetTypeInfo().IsSubclassOf(baseType);
            }
            else if (datatype.Variety == XmlSchemaDatatypeVariety.Union && !datatype.HasLexicalFacets && !datatype.HasValueFacets && _variety != XmlSchemaDatatypeVariety.Union)
            { //base type is union (not a restriction of union) and derived type is not union
                return ((Datatype_union)datatype).IsUnionBaseOf(this);
            }
            else if ((_variety == XmlSchemaDatatypeVariety.Union || _variety == XmlSchemaDatatypeVariety.List) && _restriction == null)
            { //derived type is union (not a restriction)
                return (datatype == s__anySimpleType.Datatype);
            }
            return false;
        }

Usage Example

 internal bool IsUnionBaseOf(DatatypeImplementation derivedType)
 {
     for (int i = 0; i < this.types.Length; i++)
     {
         if (derivedType.IsDerivedFrom(this.types[i].Datatype))
         {
             return true;
         }
     }
     return false;
 }
All Usage Examples Of System.Xml.Schema.DatatypeImplementation::IsDerivedFrom