Exemplo n.º 1
0
        public static bool IsAssignableFrom(this IEdmEntityType baseType, IEdmEntityType subtype)
        {
            Utils.CheckArgumentNull(baseType, nameof(baseType));
            Utils.CheckArgumentNull(subtype, nameof(subtype));

            if (baseType.TypeKind != subtype.TypeKind)
            {
                return(false);
            }

            if (subtype.IsEquivalentTo(baseType))
            {
                return(true);
            }

            IEdmStructuredType structuredSubType = subtype;

            while (structuredSubType != null)
            {
                if (structuredSubType.IsEquivalentTo(baseType))
                {
                    return(true);
                }

                structuredSubType = structuredSubType.BaseType;
            }

            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Determines if the potential base type is in the inheritance hierarchy of the type being tested.
        /// </summary>
        /// <param name="type">Type to be tested for derivation from the other type.</param>
        /// <param name="potentialBaseType">The potential base type of the type being tested.</param>
        /// <returns>True if and only if the type inherits from the potential base type.</returns>
        public static bool InheritsFrom(this IEdmStructuredType type, IEdmStructuredType potentialBaseType)
        {
            do
            {
                type = type.BaseType;
                if (type != null && type.IsEquivalentTo(potentialBaseType))
                {
                    return(true);
                }
            }while (type != null);

            return(false);
        }
Exemplo n.º 3
0
        private static void VerifyComplexType(IEdmTypeReference expectedTypeReference, IEdmType payloadType, bool failIfNotRelated)
        {
            IEdmStructuredType thisType  = expectedTypeReference.AsStructured().StructuredDefinition();
            IEdmStructuredType otherType = (IEdmStructuredType)payloadType;

            if (!thisType.IsEquivalentTo(otherType))
            {
                if (thisType.IsAssignableFrom(otherType))
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ReaderValidationUtils_DerivedComplexTypesAreNotAllowed(thisType.ODataFullName(), otherType.ODataFullName()));
                }
                if (failIfNotRelated)
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ValidationUtils_IncompatibleType(otherType.ODataFullName(), thisType.ODataFullName()));
                }
            }
        }
Exemplo n.º 4
0
 internal static bool IsAssignableFrom(this IEdmStructuredType baseType, IEdmStructuredType subtype)
 {
     if (baseType.TypeKind == subtype.TypeKind)
     {
         if (!baseType.IsODataEntityTypeKind() && !baseType.IsODataComplexTypeKind())
         {
             return(false);
         }
         for (IEdmStructuredType type = subtype; type != null; type = type.BaseType)
         {
             if (type.IsEquivalentTo(baseType))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 5
0
        internal static IEdmStructuredType GetCommonBaseType(this IEdmStructuredType firstType, IEdmStructuredType secondType)
        {
            IEdmStructuredType type;

            if (firstType.IsEquivalentTo(secondType))
            {
                return(firstType);
            }
            for (type = firstType; type != null; type = type.BaseType)
            {
                if (type.IsAssignableFrom(secondType))
                {
                    return(type);
                }
            }
            for (type = secondType; type != null; type = type.BaseType)
            {
                if (type.IsAssignableFrom(firstType))
                {
                    return(type);
                }
            }
            return(null);
        }