Exemple #1
0
        private static bool TryGetCommonPrimitiveType(
            TypeUsage type1,
            TypeUsage type2,
            out TypeUsage commonType)
        {
            commonType = (TypeUsage)null;
            if (TypeSemantics.IsPromotableTo(type1, type2))
            {
                commonType = TypeSemantics.ForgetConstraints(type2);
                return(true);
            }
            if (TypeSemantics.IsPromotableTo(type2, type1))
            {
                commonType = TypeSemantics.ForgetConstraints(type1);
                return(true);
            }
            ReadOnlyCollection <PrimitiveType> commonSuperTypes = TypeSemantics.GetPrimitiveCommonSuperTypes((PrimitiveType)type1.EdmType, (PrimitiveType)type2.EdmType);

            if (commonSuperTypes.Count == 0)
            {
                return(false);
            }
            commonType = TypeUsage.CreateDefaultTypeUsage((EdmType)commonSuperTypes[0]);
            return(null != commonType);
        }
Exemple #2
0
        internal static bool TryGetCommonType(
            TypeUsage type1,
            TypeUsage type2,
            out TypeUsage commonType)
        {
            commonType = (TypeUsage)null;
            if (type1.EdmEquals((MetadataItem)type2))
            {
                commonType = TypeSemantics.ForgetConstraints(type2);
                return(true);
            }
            if (Helper.IsPrimitiveType(type1.EdmType) && Helper.IsPrimitiveType(type2.EdmType))
            {
                return(TypeSemantics.TryGetCommonPrimitiveType(type1, type2, out commonType));
            }
            EdmType commonEdmType;

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