private static bool TryGetCommonType( PrimitiveType primitiveType1, PrimitiveType primitiveType2, out EdmType commonType) { commonType = (EdmType)null; if (TypeSemantics.IsSubTypeOf(primitiveType1, primitiveType2)) { commonType = (EdmType)primitiveType2; return(true); } if (TypeSemantics.IsSubTypeOf(primitiveType2, primitiveType1)) { commonType = (EdmType)primitiveType1; return(true); } ReadOnlyCollection <PrimitiveType> commonSuperTypes = TypeSemantics.GetPrimitiveCommonSuperTypes(primitiveType1, primitiveType2); if (commonSuperTypes.Count <= 0) { return(false); } commonType = (EdmType)commonSuperTypes[0]; return(true); }
private static bool ValidateScalarTypesAreCompatible(TypeUsage cspaceType, TypeUsage storeType) { if (Helper.IsEnumType(cspaceType.EdmType)) { return(TypeSemantics.IsSubTypeOf(TypeUsage.Create((EdmType)Helper.GetUnderlyingEdmTypeForEnumType(cspaceType.EdmType)), storeType)); } return(TypeSemantics.IsSubTypeOf(cspaceType, storeType)); }
internal static bool IsValidPolymorphicCast(TypeUsage fromType, TypeUsage toType) { if (!TypeSemantics.IsPolymorphicType(fromType) || !TypeSemantics.IsPolymorphicType(toType)) { return(false); } if (!TypeSemantics.IsStructurallyEqual(fromType, toType) && !TypeSemantics.IsSubTypeOf(fromType, toType)) { return(TypeSemantics.IsSubTypeOf(toType, fromType)); } return(true); }
// <summary> // Validates whether cspace and sspace types are compatible. // </summary> // <param name="cspaceType"> Type in C-Space. Must be a primitive or enumeration type. </param> // <param name="storeType"> C-Space equivalent of S-space Type. Must be a primitive type. </param> // <returns> // <c>true</c> if the types are compatible. <c>false</c> otherwise. // </returns> // <remarks> // This methods validate whether cspace and sspace types are compatible. The types are // compatible if: // both are primitive and the cspace type is a subtype of sspace type // or // cspace type is an enumeration type whose underlying type is a subtype of sspace type. // </remarks> private static bool ValidateScalarTypesAreCompatible(TypeUsage cspaceType, TypeUsage storeType) { DebugCheck.NotNull(cspaceType); DebugCheck.NotNull(storeType); Debug.Assert(cspaceType.EdmType.DataSpace == DataSpace.CSpace, "cspace property must have a cspace type"); Debug.Assert(storeType.EdmType.DataSpace == DataSpace.CSpace, "storeType type usage must have a sspace type"); Debug.Assert( IsScalarType(cspaceType.EdmType), "cspace property must be of a primitive or enumeration type"); Debug.Assert(IsPrimitiveType(storeType.EdmType), "storeType property must be a primitive type"); if (IsEnumType(cspaceType.EdmType)) { // For enum cspace type check whether its underlying type is a subtype of the store type. Note that // TypeSemantics.IsSubTypeOf uses only TypeUsage.EdmType for primitive types so there is no need to copy facets // from the enum type property to the underlying type TypeUsage created here since they wouldn't be used anyways. return(TypeSemantics.IsSubTypeOf(TypeUsage.Create(GetUnderlyingEdmTypeForEnumType(cspaceType.EdmType)), storeType)); } return(TypeSemantics.IsSubTypeOf(cspaceType, storeType)); }
private static bool IsPrimitiveTypePromotableTo(TypeUsage fromType, TypeUsage toType) { return(TypeSemantics.IsSubTypeOf((PrimitiveType)fromType.EdmType, (PrimitiveType)toType.EdmType)); }