private static PrimitiveType ConvertFromLegacyStoreEdmType(
            LegacyMetadata.PrimitiveType legacyPrimitiveType, DbProviderManifest providerManifest)
        {
            Debug.Assert(legacyPrimitiveType != null, "legacyPrimitiveType != null");
            Debug.Assert(providerManifest != null, "providerManifest != null");
            Debug.Assert(
                (LegacyMetadata.DataSpace) typeof(LegacyMetadata.EdmType)
                .GetProperty("DataSpace", BindingFlags.Instance | BindingFlags.NonPublic)
                .GetValue(legacyPrimitiveType) == LegacyMetadata.DataSpace.SSpace,
                "Expected SSpace type.");

            var newPrimitiveType = (PrimitiveType)_primitiveTypeConstructor.Invoke(
                BindingFlags.CreateInstance,
                null,
                new object[]
            {
                legacyPrimitiveType.Name,
                legacyPrimitiveType.NamespaceName,
                DataSpace.SSpace,
                FromLegacyPrimitiveType((LegacyMetadata.PrimitiveType)legacyPrimitiveType.BaseType),
                providerManifest
            },
                CultureInfo.InvariantCulture
                );

            SetReadOnlyMethod.Invoke(newPrimitiveType, new object[0]);

            return(newPrimitiveType);
        }
 /// <summary>
 /// The constructor for PrimitiveType, it takes in a CLR type containing the identity information
 /// </summary>
 /// <param name="clrType">The CLR type object for this primitive type</param>
 /// <param name="baseType">The base type for this primitive type</param>
 /// <param name="providerManifest">The ProviderManifest of the provider of this type</param>
 internal PrimitiveType(Type clrType,
                        PrimitiveType baseType,
                        DbProviderManifest providerManifest)
     : this(EntityUtil.GenericCheckArgumentNull(clrType, "clrType").Name, clrType.Namespace,
     DataSpace.OSpace, baseType, providerManifest)
 {
     Debug.Assert(clrType == ClrEquivalentType, "not equivalent to ClrEquivalentType");
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the EnumType class by using the specified <paramref name="name"/>,
        /// <paramref name="namespaceName"/> and <paramref name="isFlags"/>.
        /// </summary>
        /// <param name="name">The name of this enum type.</param>
        /// <param name="namespaceName">The namespace this enum type belongs to.</param>
        /// <param name="isFlags">Indicates whether the enum type is defined as flags (i.e. can be treated as a bit field).</param>
        /// <param name="underlyingType">Underlying type of this enumeration type.</param>
        /// <param name="dataSpace">DataSpace this enum type lives in. Can be either CSpace or OSpace</param>
        /// <exception cref="System.ArgumentNullException">Thrown if name or namespace arguments are null</exception>
        /// <remarks>Note that enums live only in CSpace.</remarks>
        internal EnumType(string name, string namespaceName, PrimitiveType underlyingType, bool isFlags, DataSpace dataSpace)
            : base(name, namespaceName, dataSpace)
        { 
            Debug.Assert(underlyingType != null, "underlyingType != null");
            Debug.Assert(Helper.IsSupportedEnumUnderlyingType(underlyingType.PrimitiveTypeKind), "Unsupported underlying type for enum.");
            Debug.Assert(dataSpace == DataSpace.CSpace || dataSpace == DataSpace.OSpace, "Enums can be only defined in CSpace or OSpace.");

            _isFlags = isFlags;
            _underlyingType = underlyingType;
        }
 /// <summary>
 /// Returns the primitive type corresponding to the given CLR type
 /// </summary>
 /// <param name="clrType">The CLR type for which the PrimitiveType object is retrieved</param>
 /// <param name="primitiveType">The retrieved primitive type</param>
 /// <returns>True if a primitive type is returned</returns>
 internal bool TryGetPrimitiveType(Type clrType, out PrimitiveType primitiveType)
 {
     primitiveType = null;
     PrimitiveTypeKind resolvedTypeKind;
     if (TryGetPrimitiveTypeKind(clrType, out resolvedTypeKind))
     {
         InitializePrimitiveTypes();
         primitiveType = _primitiveTypes[(int)resolvedTypeKind];
         return true;
     }
     
     return false;
 }
        /// <summary>
        /// The constructor for PrimitiveType.  It takes the required information to identify this type.
        /// </summary>
        /// <param name="name">The name of this type</param>
        /// <param name="namespaceName">The namespace name of this type</param>
        /// <param name="version">The version of this type</param>
        /// <param name="dataSpace">dataSpace in which this primitive type belongs to</param>
        /// <param name="baseType">The primitive type that this type is derived from</param>
        /// <param name="providerManifest">The ProviderManifest of the provider of this type</param>
        /// <exception cref="System.ArgumentNullException">Thrown if name, namespaceName, version, baseType or providerManifest arguments are null</exception>
        internal PrimitiveType(string name,
                             string namespaceName,
                             DataSpace dataSpace,
                             PrimitiveType baseType,
                             DbProviderManifest providerManifest)
            : base(name, namespaceName, dataSpace)
        {
            EntityUtil.GenericCheckArgumentNull(baseType, "baseType");
            EntityUtil.GenericCheckArgumentNull(providerManifest, "providerManifest");

            this.BaseType = baseType;

            Initialize(this, baseType.PrimitiveTypeKind,
                false, // isDefault
                providerManifest);
        }
        /// <summary>
        /// Add the given primitive type to the primitive type cache
        /// </summary>
        /// <param name="type">The primitive type to add</param>
        internal void Add(PrimitiveType type)
        {
            // Get to the list
            List<PrimitiveType> primitiveTypes = EntityUtil.CheckArgumentOutOfRange(_primitiveTypeMap, (int)type.PrimitiveTypeKind, "primitiveTypeKind");

            // If there isn't a list for the given model type, create one and add it
            if (primitiveTypes == null)
            {
                primitiveTypes = new List<PrimitiveType>();
                primitiveTypes.Add(type);
                _primitiveTypeMap[(int)type.PrimitiveTypeKind] = primitiveTypes;
            }
            else
            {
                primitiveTypes.Add(type);
            }
        }
            /// <summary>
            /// Attempts to get the primitive store type for the given type name. This method takes the target .NET Framework
            /// into account and only returns primitive types that are supported by the Framework that is being targeted.
            /// If a type is recognized but excluded because it is not supported by the target Framework then the excludedForTarget
            /// flag is set to true.
            /// </summary>
            internal bool TryGetStorePrimitiveType(string typeName, out PrimitiveType primitiveType, out bool excludedForTarget)
            {
                excludedForTarget = false;
                var success = ItemCollection.TryGetItem<PrimitiveType>(StoreNamespace + "." + typeName, false, out primitiveType);

                // If targetting 4.0 using 4.5 then we need to ignore geometry and geography types just like we would have done when
                // generating with 4.0. We can only get the base spatial types since we won't reverse engineer to derived spatial
                // types. We don't need to do anything for enums because we will never reverse engineer to an enum.
                if (success &&
                    _targetEntityFrameworkVersion.CompareTo(EntityFrameworkVersions.Version3) < 0 &&
                    (primitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Geography || primitiveType.PrimitiveTypeKind == PrimitiveTypeKind.Geometry))
                {
                    excludedForTarget = true;
                    primitiveType = null;
                    return false;
                }
                return success;
            }
        private static bool IsSubTypeOf(PrimitiveType subPrimitiveType, PrimitiveType superPrimitiveType)
        {
            if (object.ReferenceEquals(subPrimitiveType, superPrimitiveType))
            {
                return true;
            }

            if (Helper.AreSameSpatialUnionType(subPrimitiveType, superPrimitiveType))
            {
                return true;
            }

            objectModel.ReadOnlyCollection<PrimitiveType> superTypes = EdmProviderManifest.Instance.GetPromotionTypes(subPrimitiveType);

            return (-1 != superTypes.IndexOf(superPrimitiveType));
        }
        /// <summary>
        /// Converts a variable of type 'DataType' to type 'System.Type'
        /// </summary>
        /// <param name="type">type to convert</param>
        /// <returns>System.Type representation of type</returns>
        private static Type DataTypeToSystemType(PrimitiveType type, bool makeNullable)
        {
            if (makeNullable && type.ClrEquivalentType != typeof(string) && type.ClrEquivalentType != typeof(byte[]))
            {
                return typeof(Nullable<>).MakeGenericType(type.ClrEquivalentType);
            }

            return type.ClrEquivalentType;
        }
        /// <summary>
        /// Initializes all the primitive types
        /// </summary>
        private void InitializePrimitiveTypes()
        {
            if (_primitiveTypes != null)
            {
                return;
            }

            PrimitiveType[] primitiveTypes = new PrimitiveType[s_PrimitiveTypeCount];
            primitiveTypes[(int)PrimitiveTypeKind.Binary] = CreatePrimitiveType(typeof(Byte[]), PrimitiveTypeKind.Binary);
            primitiveTypes[(int)PrimitiveTypeKind.Boolean] = CreatePrimitiveType(typeof(Boolean), PrimitiveTypeKind.Boolean);
            primitiveTypes[(int)PrimitiveTypeKind.Byte] = CreatePrimitiveType(typeof(Byte), PrimitiveTypeKind.Byte);
            primitiveTypes[(int)PrimitiveTypeKind.DateTime] = CreatePrimitiveType(typeof(DateTime), PrimitiveTypeKind.DateTime);
            primitiveTypes[(int)PrimitiveTypeKind.Time] = CreatePrimitiveType(typeof(TimeSpan), PrimitiveTypeKind.Time);
            primitiveTypes[(int)PrimitiveTypeKind.DateTimeOffset] = CreatePrimitiveType(typeof(DateTimeOffset), PrimitiveTypeKind.DateTimeOffset);
            primitiveTypes[(int)PrimitiveTypeKind.Decimal] = CreatePrimitiveType(typeof(Decimal), PrimitiveTypeKind.Decimal);
            primitiveTypes[(int)PrimitiveTypeKind.Double] = CreatePrimitiveType(typeof(Double), PrimitiveTypeKind.Double);
            primitiveTypes[(int)PrimitiveTypeKind.Geography] = CreatePrimitiveType(typeof(DbGeography), PrimitiveTypeKind.Geography);
            primitiveTypes[(int)PrimitiveTypeKind.Geometry] = CreatePrimitiveType(typeof(DbGeometry), PrimitiveTypeKind.Geometry);
            primitiveTypes[(int)PrimitiveTypeKind.Guid] = CreatePrimitiveType(typeof(Guid), PrimitiveTypeKind.Guid);
            primitiveTypes[(int)PrimitiveTypeKind.Int16] = CreatePrimitiveType(typeof(Int16), PrimitiveTypeKind.Int16);
            primitiveTypes[(int)PrimitiveTypeKind.Int32] = CreatePrimitiveType(typeof(Int32), PrimitiveTypeKind.Int32);
            primitiveTypes[(int)PrimitiveTypeKind.Int64] = CreatePrimitiveType(typeof(Int64), PrimitiveTypeKind.Int64);
            primitiveTypes[(int)PrimitiveTypeKind.SByte] = CreatePrimitiveType(typeof(SByte), PrimitiveTypeKind.SByte);
            primitiveTypes[(int)PrimitiveTypeKind.Single] = CreatePrimitiveType(typeof(Single), PrimitiveTypeKind.Single);
            primitiveTypes[(int)PrimitiveTypeKind.String] = CreatePrimitiveType(typeof(String), PrimitiveTypeKind.String);

            System.Collections.ObjectModel.ReadOnlyCollection<PrimitiveType> readOnlyTypes = new System.Collections.ObjectModel.ReadOnlyCollection<PrimitiveType>(primitiveTypes);

            // Set the result to _primitiveTypes at the end
            Interlocked.CompareExchange<System.Collections.ObjectModel.ReadOnlyCollection<PrimitiveType>>(ref _primitiveTypes, readOnlyTypes, null);
        }
        /// <summary>
        /// Try and get the mapped type for the given primitiveTypeKind in the given dataspace
        /// </summary>
        /// <param name="primitiveTypeKind">The primitive type kind of the primitive type to retrieve</param>
        /// <param name="facets">The facets to use in picking the primitive type</param>
        /// <param name="type">The resulting type</param>
        /// <returns>Whether a type was retrieved or not</returns>
        internal bool TryGetType(PrimitiveTypeKind primitiveTypeKind, IEnumerable<Facet> facets, out PrimitiveType type)
        {
            type = null;

            // Now, see if we have any types for this model type, if so, loop through to find the best matching one
            List<PrimitiveType> primitiveTypes = EntityUtil.CheckArgumentOutOfRange(_primitiveTypeMap, (int)primitiveTypeKind, "primitiveTypeKind");
            if ((null != primitiveTypes) && (0 < primitiveTypes.Count))
            {
                if (primitiveTypes.Count == 1)
                {
                    type = primitiveTypes[0];
                    return true;
                }

                if (facets == null)
                {
                    FacetDescription[] facetDescriptions = EdmProviderManifest.GetInitialFacetDescriptions(primitiveTypeKind);
                    if (facetDescriptions == null)
                    {
                        type = primitiveTypes[0];
                        return true;
                    }

                    Debug.Assert(facetDescriptions.Length > 0);
                    facets = CacheForPrimitiveTypes.CreateInitialFacets(facetDescriptions);
                }

                Debug.Assert(type == null, "type must be null here");
                bool isMaxLengthSentinel = false;

                // Create a dictionary of facets for easy lookup
                foreach (Facet facet in facets)
                {
                    if ((primitiveTypeKind == PrimitiveTypeKind.String ||
                         primitiveTypeKind == PrimitiveTypeKind.Binary) &&
                        facet.Value != null &&
                        facet.Name == EdmProviderManifest.MaxLengthFacetName &&
                        Helper.IsUnboundedFacetValue(facet))
                    {
                        // MaxLength has the sentinel value. So this facet need not be added.
                        isMaxLengthSentinel = true;
                        continue;
                    }
                }

                int maxLength = 0;
                // Find a primitive type with the matching constraint
                foreach (PrimitiveType primitiveType in primitiveTypes)
                {
                    if (isMaxLengthSentinel)
                    {
                        if (type == null)
                        {
                            type = primitiveType;
                            maxLength = Helper.GetFacet(primitiveType.FacetDescriptions, EdmProviderManifest.MaxLengthFacetName).MaxValue.Value;
                        }
                        else
                        {
                            int newMaxLength = Helper.GetFacet(primitiveType.FacetDescriptions, EdmProviderManifest.MaxLengthFacetName).MaxValue.Value;
                            if (newMaxLength > maxLength)
                            {
                                type = primitiveType;
                                maxLength = newMaxLength;
                            }
                        }
                    }
                    else
                    {
                        type = primitiveType;
                        break;
                    }
                }

                Debug.Assert(type != null);
                return true;
            }

            return false;
        }
        protected override void Visit(PrimitiveType primitiveType)
        {
            int index;
            if (!this.AddObjectToSeenListAndHashBuilder(primitiveType, out index))
            {
                return;
            }

            this.AddObjectStartDumpToHashBuilder(primitiveType, index);

            #region Inner data visit
            this.AddObjectContentToHashBuilder(primitiveType.Name);
            this.AddObjectContentToHashBuilder(primitiveType.NamespaceName);

            base.Visit(primitiveType);

            #endregion

            this.AddObjectEndDumpToHashBuilder();
        }
 protected virtual void Visit(PrimitiveType primitiveType)
 {
 }
 private static PrimitiveType FromLegacyPrimitiveType(LegacyMetadata.PrimitiveType legacyPrimitiveType)
 {
     return
         (PrimitiveType.GetEdmPrimitiveType((PrimitiveTypeKind)(int)legacyPrimitiveType.PrimitiveTypeKind));
 }
        /// <summary>
        /// Returns the list of super-types for the given primitiveType
        /// </summary>
        /// <param name="primitiveType"></param>
        /// <returns></returns>
        internal ReadOnlyCollection<PrimitiveType> GetPromotionTypes(PrimitiveType primitiveType)
        {
            InitializePromotableTypes();

            return _promotionTypes[(int)primitiveType.PrimitiveTypeKind];
        }
 /// <summary>
 /// Perform initialization that's common across all constructors
 /// </summary>
 /// <param name="primitiveType">The primitive type to initialize</param>
 /// <param name="primitiveTypeKind">The primitive type kind of this primitive type</param>
 /// <param name="isDefaultType">When true this is the default type to return when a type is asked for by PrimitiveTypeKind</param>
 /// <param name="providerManifest">The ProviderManifest of the provider of this type</param>
 internal static void Initialize(PrimitiveType primitiveType,
                                               PrimitiveTypeKind primitiveTypeKind,
                                               bool isDefaultType,
                                               DbProviderManifest providerManifest)
 {
     primitiveType._primitiveTypeKind = primitiveTypeKind;
     primitiveType._providerManifest = providerManifest;
 }
 protected bool TryGetPrimitiveType(Type type, out PrimitiveType primitiveType)
 {
     return ClrProviderManifest.Instance.TryGetPrimitiveType(Nullable.GetUnderlyingType(type) ?? type, out primitiveType);
 }
        /// <summary>
        /// Boostrapping all the primitive types for the EDM Provider Manifest
        /// </summary>
        private void InitializePrimitiveTypes()
        {
            if (_primitiveTypes != null)
            {
                return;
            }

            PrimitiveType[] primitiveTypes = new PrimitiveType[EdmConstants.NumPrimitiveTypes];
            primitiveTypes[(int)PrimitiveTypeKind.Binary] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Boolean] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Byte] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.DateTime] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Decimal] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Double] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Single] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Guid] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Int16] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Int32] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Int64] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.SByte] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.String] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Time] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.DateTimeOffset] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Geometry] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeometryPoint] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeometryLineString] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeometryPolygon] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeometryMultiPoint] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeometryMultiLineString] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeometryMultiPolygon] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeometryCollection] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.Geography] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeographyPoint] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeographyLineString] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeographyPolygon] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeographyMultiPoint] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeographyMultiLineString] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeographyMultiPolygon] = new PrimitiveType();
            primitiveTypes[(int)PrimitiveTypeKind.GeographyCollection] = new PrimitiveType();

            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Binary], PrimitiveTypeKind.Binary, EdmConstants.Binary, typeof(Byte[]));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Boolean], PrimitiveTypeKind.Boolean, EdmConstants.Boolean, typeof(Boolean));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Byte], PrimitiveTypeKind.Byte, EdmConstants.Byte, typeof(Byte));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.DateTime], PrimitiveTypeKind.DateTime, EdmConstants.DateTime, typeof(DateTime));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Decimal], PrimitiveTypeKind.Decimal, EdmConstants.Decimal, typeof(Decimal));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Double], PrimitiveTypeKind.Double, EdmConstants.Double, typeof(Double));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Single], PrimitiveTypeKind.Single, EdmConstants.Single, typeof(Single));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Guid], PrimitiveTypeKind.Guid, EdmConstants.Guid, typeof(Guid));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Int16], PrimitiveTypeKind.Int16, EdmConstants.Int16, typeof(Int16));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Int32], PrimitiveTypeKind.Int32, EdmConstants.Int32, typeof(Int32));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Int64], PrimitiveTypeKind.Int64, EdmConstants.Int64, typeof(Int64));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.SByte], PrimitiveTypeKind.SByte, EdmConstants.SByte, typeof(SByte));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.String], PrimitiveTypeKind.String, EdmConstants.String, typeof(String));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Time], PrimitiveTypeKind.Time, EdmConstants.Time, typeof(TimeSpan));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.DateTimeOffset], PrimitiveTypeKind.DateTimeOffset, EdmConstants.DateTimeOffset, typeof(DateTimeOffset));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Geography], PrimitiveTypeKind.Geography, EdmConstants.Geography, typeof(DbGeography));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeographyPoint], PrimitiveTypeKind.GeographyPoint, EdmConstants.GeographyPoint, typeof(DbGeography));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeographyLineString], PrimitiveTypeKind.GeographyLineString, EdmConstants.GeographyLineString, typeof(DbGeography));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeographyPolygon], PrimitiveTypeKind.GeographyPolygon, EdmConstants.GeographyPolygon, typeof(DbGeography));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeographyMultiPoint], PrimitiveTypeKind.GeographyMultiPoint, EdmConstants.GeographyMultiPoint, typeof(DbGeography));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeographyMultiLineString], PrimitiveTypeKind.GeographyMultiLineString, EdmConstants.GeographyMultiLineString, typeof(DbGeography));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeographyMultiPolygon], PrimitiveTypeKind.GeographyMultiPolygon, EdmConstants.GeographyMultiPolygon, typeof(DbGeography));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeographyCollection], PrimitiveTypeKind.GeographyCollection, EdmConstants.GeographyCollection, typeof(DbGeography));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.Geometry], PrimitiveTypeKind.Geometry, EdmConstants.Geometry, typeof(DbGeometry));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeometryPoint], PrimitiveTypeKind.GeometryPoint, EdmConstants.GeometryPoint, typeof(DbGeometry));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeometryLineString], PrimitiveTypeKind.GeometryLineString, EdmConstants.GeometryLineString, typeof(DbGeometry));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeometryPolygon], PrimitiveTypeKind.GeometryPolygon, EdmConstants.GeometryPolygon, typeof(DbGeometry));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeometryMultiPoint], PrimitiveTypeKind.GeometryMultiPoint, EdmConstants.GeometryMultiPoint, typeof(DbGeometry));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeometryMultiLineString], PrimitiveTypeKind.GeometryMultiLineString, EdmConstants.GeometryMultiLineString, typeof(DbGeometry));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeometryMultiPolygon], PrimitiveTypeKind.GeometryMultiPolygon, EdmConstants.GeometryMultiPolygon, typeof(DbGeometry));
            InitializePrimitiveType(primitiveTypes[(int)PrimitiveTypeKind.GeometryCollection], PrimitiveTypeKind.GeometryCollection, EdmConstants.GeometryCollection, typeof(DbGeometry));
           
            // Set all primitive types to be readonly
            foreach (PrimitiveType primitiveType in primitiveTypes)
            {
                primitiveType.ProviderManifest = this;
                primitiveType.SetReadOnly();
            }

            System.Collections.ObjectModel.ReadOnlyCollection<PrimitiveType> readOnlyTypes = new System.Collections.ObjectModel.ReadOnlyCollection<PrimitiveType>(primitiveTypes);

            // Set the result to _primitiveTypes at the end
            Interlocked.CompareExchange<System.Collections.ObjectModel.ReadOnlyCollection<PrimitiveType>>(ref _primitiveTypes, readOnlyTypes, null);
        }
Esempio n. 19
0
        /// <summary>
        /// returns the primitive type for a given primitive type kind.
        /// </summary>
        /// <param name="primitiveTypeKind"></param>
        /// <param name="primitiveType"></param>
        /// <returns></returns>
        internal virtual bool TryGetMappedPrimitiveType(PrimitiveTypeKind primitiveTypeKind, out PrimitiveType primitiveType)
        {
            primitiveType = m_metadataWorkspace.GetMappedPrimitiveType(primitiveTypeKind, DataSpace.CSpace);

            return (null != primitiveType);
        }
 /// <summary>
 /// Initialize all the primitive type with the given primitive type kind and name
 /// </summary>
 /// <param name="primitiveType">The primitive type to initialize</param>
 /// <param name="primitiveTypeKind">Type of the primitive type which is getting initialized</param>
 /// <param name="name">name of the built in type</param>
 /// <param name="clrType">the CLR Type of that maps to the EDM PrimitiveType</param>
 private void InitializePrimitiveType(PrimitiveType primitiveType,
                                      PrimitiveTypeKind primitiveTypeKind,
                                      string name,
                                      Type clrType)
 {
     // Only null types are not abstract and they are sealed, all others are abstract and unsealed
     EdmType.Initialize(primitiveType, name,
                        EdmConstants.EdmNamespace,
                        DataSpace.CSpace,
                        true /* isabstract */,
                        null /* baseType */);
     PrimitiveType.Initialize(primitiveType,
                              primitiveTypeKind,
                              true, // isDefault
                              this);
     Debug.Assert(clrType == primitiveType.ClrEquivalentType, "ClrEquivalentType mismatch");
 }
 /// <summary>
 /// Initialize the primitive type with the given 
 /// </summary>
 /// <param name="clrType">The CLR type of this type</param>
 /// <param name="primitiveTypeKind">The primitive type kind of the primitive type</param>
 private PrimitiveType CreatePrimitiveType(Type clrType, PrimitiveTypeKind primitiveTypeKind)
 {
     // Figures out the base type
     PrimitiveType baseType = MetadataItem.EdmProviderManifest.GetPrimitiveType(primitiveTypeKind);
     PrimitiveType primitiveType = new PrimitiveType(clrType, baseType, this);
     primitiveType.SetReadOnly();
     return primitiveType;
 }
        /// <summary>
        /// Returns the list of super-types for the given primitiveType
        /// </summary>
        /// <param name="primitiveType"></param>
        /// <returns></returns>
        internal System.Collections.ObjectModel.ReadOnlyCollection<PrimitiveType> GetPromotionTypes(PrimitiveType primitiveType)
        {
            InitializePromotableTypes();

            return _promotionTypes[(int)primitiveType.PrimitiveTypeKind];
        }
Esempio n. 23
0
 private static object GetSpatialValueFromProviderValue(object spatialValue, PrimitiveType parameterType, EntityConnection connection)
 {
     DbProviderServices providerServices = DbProviderServices.GetProviderServices(connection.StoreConnection);
     StoreItemCollection storeItemCollection = (StoreItemCollection)connection.GetMetadataWorkspace().GetItemCollection(DataSpace.SSpace);
     DbSpatialServices spatialServices = providerServices.GetSpatialServices(storeItemCollection.StoreProviderManifestToken);
     if (Helper.IsGeographicType(parameterType))
     {
         return spatialServices.GeographyFromProviderValue(spatialValue);
     }
     else
     {
         Debug.Assert(Helper.IsGeometricType(parameterType));
         return spatialServices.GeometryFromProviderValue(spatialValue);
     }
 }
Esempio n. 24
0
 internal static bool TryGetDbTypeFromPrimitiveType(PrimitiveType type, out DbType dbType)
 {
     switch (type.PrimitiveTypeKind)
     {
         case PrimitiveTypeKind.Binary:
             dbType = DbType.Binary; 
             return true;
         case PrimitiveTypeKind.Boolean:
             dbType = DbType.Boolean; 
             return true;
         case PrimitiveTypeKind.Byte:
             dbType = DbType.Byte; 
             return true;
         case PrimitiveTypeKind.DateTime:
             dbType = DbType.DateTime; 
             return true;
         case PrimitiveTypeKind.Time:
             dbType = DbType.Time; 
             return true;
         case PrimitiveTypeKind.DateTimeOffset:
             dbType = DbType.DateTimeOffset; 
             return true;
         case PrimitiveTypeKind.Decimal:
             dbType = DbType.Decimal; 
             return true;
         case PrimitiveTypeKind.Double:
             dbType = DbType.Double; 
             return true;
         case PrimitiveTypeKind.Guid:
             dbType = DbType.Guid; 
             return true;
         case PrimitiveTypeKind.Single:
             dbType = DbType.Single; 
             return true;
         case PrimitiveTypeKind.SByte:
             dbType = DbType.SByte; 
             return true;
         case PrimitiveTypeKind.Int16:
             dbType = DbType.Int16; 
             return true;
         case PrimitiveTypeKind.Int32:
             dbType = DbType.Int32; 
             return true;
         case PrimitiveTypeKind.Int64:
             dbType = DbType.Int64; 
             return true;
         case PrimitiveTypeKind.String:
             dbType = DbType.String; 
             return true;
         default:
             dbType = default(DbType);
             return  false;
     }
 }
Esempio n. 25
0
 /// <summary>
 /// Initializes a new instance of the EnumType class. This default constructor is used for bootstraping
 /// </summary>
 internal EnumType()
 {
     _underlyingType = PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32);
     _isFlags = false;
 }
Esempio n. 26
0
 /// <summary>
 /// Construct an internal (not from schema) CDM scalar type
 /// </summary>
 /// <param name="parentElement">the owning schema</param>
 /// <param name="typeName">the naem of the type</param>
 /// <param name="primitiveType">the PrimitiveTypeKind of the type</param>
 internal ScalarType(Schema parentElement, string typeName, PrimitiveType primitiveType)
 : base(parentElement)
 {
     Name = typeName;
     _primitiveType = primitiveType;
 }
 /// <summary>
 /// Returns the list of common super types of two primitive types.
 /// </summary>
 /// <param name="primitiveType1"></param>
 /// <param name="primitiveType2"></param>
 /// <returns></returns>
 private static objectModel.ReadOnlyCollection<PrimitiveType> GetPrimitiveCommonSuperTypes(PrimitiveType primitiveType1, PrimitiveType primitiveType2)
 {
     ComputeCommonTypeClosure();
     return _commonTypeClosure[(int)primitiveType1.PrimitiveTypeKind, (int)primitiveType2.PrimitiveTypeKind];
 }
            // Find "sanctioned" default value
            private static void GetPropagatorResultForPrimitiveType(PrimitiveType primitiveType, out PropagatorResult result)
            {
                object value;
                PrimitiveTypeKind primitiveTypeKind = primitiveType.PrimitiveTypeKind;
                if (!s_typeDefaultMap.TryGetValue(primitiveTypeKind, out value))
                {
                    // If none exists, default to lowest common denominator for constants
                    value = default(byte);
                }

                // Return a new constant expression flagged as unknown since the value is only there for
                // show. (Not entirely for show, because null constraints may require a value for a record,
                // whether that record is a placeholder or not).
                result = PropagatorResult.CreateSimpleValue(PropagatorFlags.NoFlags, value);
            }
        private static bool TryGetCommonType(PrimitiveType primitiveType1, PrimitiveType primitiveType2, out EdmType commonType)
        {
            commonType = null;

            if (IsSubTypeOf(primitiveType1, primitiveType2))
            {
                commonType = primitiveType2;
                return true;
            }

            if (IsSubTypeOf(primitiveType2, primitiveType1))
            {
                commonType = primitiveType1;
                return true;
            }

            objectModel.ReadOnlyCollection<PrimitiveType> superTypes = GetPrimitiveCommonSuperTypes(primitiveType1, primitiveType2);
            if (superTypes.Count > 0)
            {
                commonType = superTypes[0];
                return true;
            }

            return false;
        }
Esempio n. 30
0
 /// <summary>
 /// Validate an GetPrimitiveType object
 /// </summary>
 /// <param name="item">The GetPrimitiveType object to validate</param>
 /// <param name="errors">An error collection for adding validation errors</param>
 /// <param name="validatedItems">A dictionary keeping track of items that have been validated</param>
 private void ValidatePrimitiveType(PrimitiveType item, List <EdmItemError> errors, HashSet <MetadataItem> validatedItems)
 {
     ValidateSimpleType(item, errors, validatedItems);
 }