internal static bool IsPromotableTo(TypeUsage fromType, TypeUsage toType) { if (toType.EdmType.EdmEquals((MetadataItem)fromType.EdmType)) { return(true); } if (Helper.IsPrimitiveType(fromType.EdmType) && Helper.IsPrimitiveType(toType.EdmType)) { return(TypeSemantics.IsPrimitiveTypePromotableTo(fromType, toType)); } if (Helper.IsCollectionType((GlobalItem)fromType.EdmType) && Helper.IsCollectionType((GlobalItem)toType.EdmType)) { return(TypeSemantics.IsPromotableTo(TypeHelpers.GetElementTypeUsage(fromType), TypeHelpers.GetElementTypeUsage(toType))); } if (Helper.IsEntityTypeBase(fromType.EdmType) && Helper.IsEntityTypeBase(toType.EdmType)) { return(fromType.EdmType.IsSubtypeOf(toType.EdmType)); } if (Helper.IsRefType((GlobalItem)fromType.EdmType) && Helper.IsRefType((GlobalItem)toType.EdmType)) { return(TypeSemantics.IsPromotableTo(TypeHelpers.GetElementTypeUsage(fromType), TypeHelpers.GetElementTypeUsage(toType))); } if (Helper.IsRowType((GlobalItem)fromType.EdmType) && Helper.IsRowType((GlobalItem)toType.EdmType)) { return(TypeSemantics.IsPromotableTo((RowType)fromType.EdmType, (RowType)toType.EdmType)); } return(false); }
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); }
internal static bool IsStructurallyEqualOrPromotableTo(TypeUsage fromType, TypeUsage toType) { if (!TypeSemantics.IsStructurallyEqual(fromType, toType)) { return(TypeSemantics.IsPromotableTo(fromType, toType)); } return(true); }
private static bool IsPromotableTo(RowType fromRowType, RowType toRowType) { if (fromRowType.Properties.Count != toRowType.Properties.Count) { return(false); } for (int index = 0; index < fromRowType.Properties.Count; ++index) { if (!TypeSemantics.IsPromotableTo(fromRowType.Properties[index].TypeUsage, toRowType.Properties[index].TypeUsage)) { return(false); } } return(true); }