示例#1
0
 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);
 }
示例#2
0
        private static bool TryGetCommonType(
            CollectionType collectionType1,
            CollectionType collectionType2,
            out EdmType commonType)
        {
            TypeUsage commonType1 = (TypeUsage)null;

            if (!TypeSemantics.TryGetCommonType(collectionType1.TypeUsage, collectionType2.TypeUsage, out commonType1))
            {
                commonType = (EdmType)null;
                return(false);
            }
            commonType = (EdmType) new CollectionType(commonType1);
            return(true);
        }
示例#3
0
 private static bool IsEqualComparable(EdmType edmType)
 {
     if (Helper.IsPrimitiveType(edmType) || Helper.IsRefType((GlobalItem)edmType) || (Helper.IsEntityType(edmType) || Helper.IsEnumType(edmType)))
     {
         return(true);
     }
     if (!Helper.IsRowType((GlobalItem)edmType))
     {
         return(false);
     }
     foreach (EdmMember property in ((RowType)edmType).Properties)
     {
         if (!TypeSemantics.IsEqualComparable(property.TypeUsage))
         {
             return(false);
         }
     }
     return(true);
 }
示例#4
0
        // <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));
        }
示例#5
0
        private static bool CompareTypes(TypeUsage fromType, TypeUsage toType, bool equivalenceOnly)
        {
            if (object.ReferenceEquals((object)fromType, (object)toType))
            {
                return(true);
            }
            if (fromType.EdmType.BuiltInTypeKind != toType.EdmType.BuiltInTypeKind)
            {
                return(false);
            }
            if (fromType.EdmType.BuiltInTypeKind == BuiltInTypeKind.CollectionType)
            {
                return(TypeSemantics.CompareTypes(((CollectionType)fromType.EdmType).TypeUsage, ((CollectionType)toType.EdmType).TypeUsage, equivalenceOnly));
            }
            if (fromType.EdmType.BuiltInTypeKind == BuiltInTypeKind.RefType)
            {
                return(((RefType)fromType.EdmType).ElementType.EdmEquals((MetadataItem)((RefType)toType.EdmType).ElementType));
            }
            if (fromType.EdmType.BuiltInTypeKind != BuiltInTypeKind.RowType)
            {
                return(fromType.EdmType.EdmEquals((MetadataItem)toType.EdmType));
            }
            RowType edmType1 = (RowType)fromType.EdmType;
            RowType edmType2 = (RowType)toType.EdmType;

            if (edmType1.Properties.Count != edmType2.Properties.Count)
            {
                return(false);
            }
            for (int index = 0; index < edmType1.Properties.Count; ++index)
            {
                EdmProperty property1 = edmType1.Properties[index];
                EdmProperty property2 = edmType2.Properties[index];
                if (!equivalenceOnly && property1.Name != property2.Name || !TypeSemantics.CompareTypes(property1.TypeUsage, property2.TypeUsage, equivalenceOnly))
                {
                    return(false);
                }
            }
            return(true);
        }
示例#6
0
        private static void ComputeCommonTypeClosure()
        {
            if (TypeSemantics._commonTypeClosure != null)
            {
                return;
            }
            ReadOnlyCollection <PrimitiveType>[,] readOnlyCollectionArray = new ReadOnlyCollection <PrimitiveType> [31, 31];
            for (int index = 0; index < 31; ++index)
            {
                readOnlyCollectionArray[index, index] = Helper.EmptyPrimitiveTypeReadOnlyCollection;
            }
            ReadOnlyCollection <PrimitiveType> storeTypes = EdmProviderManifest.Instance.GetStoreTypes();

            for (int index1 = 0; index1 < 31; ++index1)
            {
                for (int index2 = 0; index2 < index1; ++index2)
                {
                    readOnlyCollectionArray[index1, index2] = TypeSemantics.Intersect((IList <PrimitiveType>)EdmProviderManifest.Instance.GetPromotionTypes(storeTypes[index1]), (IList <PrimitiveType>)EdmProviderManifest.Instance.GetPromotionTypes(storeTypes[index2]));
                    readOnlyCollectionArray[index2, index1] = readOnlyCollectionArray[index1, index2];
                }
            }
            Interlocked.CompareExchange <ReadOnlyCollection <PrimitiveType> [, ]>(ref TypeSemantics._commonTypeClosure, readOnlyCollectionArray, (ReadOnlyCollection <PrimitiveType> [, ])null);
        }
示例#7
0
        /// <summary>
        ///     Returns a Model type usage for a provider type
        /// </summary>
        /// <returns> model (CSpace) type usage </returns>
        internal TypeUsage GetModelTypeUsage()
        {
            if (_modelTypeUsage == null)
            {
                var edmType = EdmType;

                // If the edm type is already a cspace type, return the same type
                if (edmType.DataSpace == DataSpace.CSpace ||
                    edmType.DataSpace == DataSpace.OSpace)
                {
                    return(this);
                }

                TypeUsage result;
                if (Helper.IsRowType(edmType))
                {
                    var sspaceRowType = (RowType)edmType;
                    var properties    = new EdmProperty[sspaceRowType.Properties.Count];
                    for (var i = 0; i < properties.Length; i++)
                    {
                        var sspaceProperty = sspaceRowType.Properties[i];
                        var newTypeUsage   = sspaceProperty.TypeUsage.GetModelTypeUsage();
                        properties[i] = new EdmProperty(sspaceProperty.Name, newTypeUsage);
                    }
                    var edmRowType = new RowType(properties, sspaceRowType.InitializerMetadata);
                    result = Create(edmRowType, Facets);
                }
                else if (Helper.IsCollectionType(edmType))
                {
                    var sspaceCollectionType = ((CollectionType)edmType);
                    var newTypeUsage         = sspaceCollectionType.TypeUsage.GetModelTypeUsage();
                    result = Create(new CollectionType(newTypeUsage), Facets);
                }
                else if (Helper.IsRefType(edmType))
                {
                    Debug.Assert(((RefType)edmType).ElementType.DataSpace == DataSpace.CSpace);
                    result = this;
                }
                else if (Helper.IsPrimitiveType(edmType))
                {
                    result = ((PrimitiveType)edmType).ProviderManifest.GetEdmType(this);

                    if (result == null)
                    {
                        throw new ProviderIncompatibleException(Strings.Mapping_ProviderReturnsNullType(ToString()));
                    }

                    if (!TypeSemantics.IsNullable(this))
                    {
                        result = Create(
                            result.EdmType,
                            OverrideFacetValues(
                                result.Facets,
                                new FacetValues
                        {
                            Nullable = false
                        }));
                    }
                }
                else if (Helper.IsEntityTypeBase(edmType) ||
                         Helper.IsComplexType(edmType))
                {
                    result = this;
                }
                else
                {
                    Debug.Assert(false, "Unexpected type found in entity data reader");
                    return(null);
                }
                Interlocked.CompareExchange(ref _modelTypeUsage, result, null);
            }
            return(_modelTypeUsage);
        }
示例#8
0
 private static bool IsPrimitiveTypePromotableTo(TypeUsage fromType, TypeUsage toType)
 {
     return(TypeSemantics.IsSubTypeOf((PrimitiveType)fromType.EdmType, (PrimitiveType)toType.EdmType));
 }
示例#9
0
 internal static bool IsStructurallyEqualOrPromotableTo(EdmType fromType, EdmType toType)
 {
     return(TypeSemantics.IsStructurallyEqualOrPromotableTo(TypeUsage.Create(fromType), TypeUsage.Create(toType)));
 }
示例#10
0
 internal static bool IsNullable(EdmMember edmMember)
 {
     return(TypeSemantics.IsNullable(edmMember.TypeUsage));
 }
示例#11
0
 internal static bool IsOrderComparable(TypeUsage type)
 {
     return(TypeSemantics.IsOrderComparable(type.EdmType));
 }
示例#12
0
 internal static bool IsBooleanType(TypeUsage type)
 {
     return(TypeSemantics.IsPrimitiveType(type, PrimitiveTypeKind.Boolean));
 }
示例#13
0
 internal static bool IsStructurallyEqual(TypeUsage fromType, TypeUsage toType)
 {
     return(TypeSemantics.CompareTypes(fromType, toType, true));
 }
示例#14
0
 internal static bool IsEqual(TypeUsage type1, TypeUsage type2)
 {
     return(TypeSemantics.CompareTypes(type1, type2, false));
 }
示例#15
0
 internal static bool IsScalarType(TypeUsage type)
 {
     return(TypeSemantics.IsScalarType(type.EdmType));
 }
示例#16
0
 internal static bool IsValidPolymorphicCast(EdmType fromEdmType, EdmType toEdmType)
 {
     return(TypeSemantics.IsValidPolymorphicCast(TypeUsage.Create(fromEdmType), TypeUsage.Create(toEdmType)));
 }