Example #1
0
        /// <summary>
        /// Determines if a common super type (LUB) exists between type1 and type2.
        /// </summary>
        /// <param name="type1"></param>
        /// <param name="type2"></param>
        /// <param name="commonType"></param>
        /// <returns>
        /// true if a common super type between type1 and type2 exists and out commonType represents the common super type.
        /// false otherwise along with commonType as null
        /// </returns>
        internal static bool TryGetCommonType(TypeUsage type1, TypeUsage type2, out TypeUsage commonType)
        {
            Debug.Assert(type1 != null, "type1 must not be NULL");
            Debug.Assert(type2 != null, "type2 must not be NULL");

            commonType = null;

            if (type1.EdmEquals(type2))
            {
                commonType = ForgetConstraints(type2);
                return(true);
            }

            if (Helper.IsPrimitiveType(type1.EdmType) && Helper.IsPrimitiveType(type2.EdmType))
            {
                return(TryGetCommonPrimitiveType(type1, type2, out commonType));
            }

            EdmType commonEdmType;

            if (TryGetCommonType(type1.EdmType, type2.EdmType, out commonEdmType))
            {
                commonType = ForgetConstraints(TypeUsage.Create(commonEdmType));
                return(true);
            }

            commonType = null;
            return(false);
        }
Example #2
0
        /// <summary>
        /// Get the "new" type corresponding to the input type. For structured types,
        /// we return the flattened record type.
        /// For collections of structured type, we return a new collection type of the corresponding flattened
        /// type.
        /// For enum types we return the underlying type of the enum type.
        /// For strong spatial types we return the union type that includes the strong spatial type.
        /// For everything else, we return the input type
        /// </summary>
        /// <param name="type">the original type</param>
        /// <returns>the new type (if any)</returns>
        private md.TypeUsage GetNewType(md.TypeUsage type)
        {
            if (TypeUtils.IsStructuredType(type))
            {
                TypeInfo typeInfo = GetTypeInfo(type);
                return(typeInfo.FlattenedTypeUsage);
            }
            md.TypeUsage elementType;
            if (TypeHelpers.TryGetCollectionElementType(type, out elementType))
            {
                md.TypeUsage newElementType = GetNewType(elementType);
                if (newElementType.EdmEquals(elementType))
                {
                    return(type);
                }
                else
                {
                    return(TypeHelpers.CreateCollectionTypeUsage(newElementType));
                }
            }

            if (TypeUtils.IsEnumerationType(type))
            {
                return(TypeHelpers.CreateEnumUnderlyingTypeUsage(type));
            }

            if (md.TypeSemantics.IsStrongSpatialType(type))
            {
                return(TypeHelpers.CreateSpatialUnionTypeUsage(type));
            }

            // simple scalar
            return(type);
        }
Example #3
0
        /// <summary>
        /// determines if subType is equal to or a sub-type of superType.
        /// </summary>
        /// <param name="subType"></param>
        /// <param name="superType"></param>
        /// <returns>true if subType is equal to or a sub-type of superType, false otherwise</returns>
        internal static bool IsSubTypeOf(TypeUsage subType, TypeUsage superType)
        {
            Debug.Assert(subType != null, "subType must not be NULL");
            Debug.Assert(superType != null, "superType must not be NULL");

            if (subType.EdmEquals(superType))
            {
                return(true);
            }

            if (Helper.IsPrimitiveType(subType.EdmType) && Helper.IsPrimitiveType(superType.EdmType))
            {
                return(IsPrimitiveTypeSubTypeOf(subType, superType));
            }

            return(subType.IsSubtypeOf(superType));
        }