ClrProviderManifest.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / Metadata / Edm / Provider / ClrProviderManifest.cs / 1305376 / ClrProviderManifest.cs

                            //---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner       [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 

using System.Collections.Generic; 
using System.Data.Common;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Threading; 
using System.Linq;
 
namespace System.Data.Metadata.Edm 
{
    internal class ClrProviderManifest : DbProviderManifest 
    {
        private const int s_PrimitiveTypeCount = 15;
        private System.Collections.ObjectModel.ReadOnlyCollection _primitiveTypes;
        private static ClrProviderManifest _instance = new ClrProviderManifest(); 

        ///  
        /// A private constructor to prevent other places from instantiating this class 
        /// 
        private ClrProviderManifest() 
        {
        }

        ///  
        /// Gets the EDM provider manifest singleton instance
        ///  
        internal static ClrProviderManifest Instance 
        {
            get 
            {
                return _instance;
            }
        } 

        ///  
        /// Returns the namespace used by this provider manifest 
        /// 
        public override string NamespaceName 
        {
            get { return EdmConstants.ClrPrimitiveTypeNamespace; }
        }
 
        /// 
        /// Returns the primitive type corresponding to the given CLR type 
        ///  
        /// The CLR type for which the PrimitiveType object is retrieved
        /// The retrieved primitive type 
        /// True if a primitive type is returned
        internal bool TryGetPrimitiveType(Type clrType, out PrimitiveType primitiveType)
        {
            primitiveType = null; 
            InitializePrimitiveTypes();
            for (int i = 0 ; i < _primitiveTypes.Count ; i++ ) 
            { 
                if (_primitiveTypes[i].ClrEquivalentType.Equals(clrType))
                { 
                    primitiveType = _primitiveTypes[i];
                    return true;
                }
            } 
            return false;
        } 
 
        /// 
        /// Returns all the functions in this provider manifest 
        /// 
        /// A collection of functions
        public override System.Collections.ObjectModel.ReadOnlyCollection GetStoreFunctions()
        { 
            return Helper.EmptyEdmFunctionReadOnlyCollection;
        } 
 
        /// 
        /// Returns all the FacetDescriptions for a particular type 
        /// 
        /// the type to return FacetDescriptions for.
        /// The FacetDescriptions for the type given.
        public override System.Collections.ObjectModel.ReadOnlyCollection GetFacetDescriptions(EdmType type) 
        {
            if (Helper.IsPrimitiveType(type) && ((PrimitiveType)type).DataSpace == DataSpace.OSpace) 
            { 
                // we don't have our own facets, just defer to the edm primitive type facets
                PrimitiveType basePrimitive = (PrimitiveType)type.BaseType; 
                return basePrimitive.ProviderManifest.GetFacetDescriptions(basePrimitive);
            }

            return Helper.EmptyFacetDescriptionEnumerable; 
        }
 
        ///  
        /// Initializes all the primitive types
        ///  
        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.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);
 
            for (int i = 0; i < primitiveTypes.Length; i++) 
            {
                primitiveTypes[i].SetReadOnly(); 
            }

            System.Collections.ObjectModel.ReadOnlyCollection readOnlyTypes = new System.Collections.ObjectModel.ReadOnlyCollection(primitiveTypes);
 
            // Set the result to _primitiveTypes at the end
            Interlocked.CompareExchange>(ref _primitiveTypes, readOnlyTypes, null); 
        } 

        ///  
        /// Initialize the primitive type with the given
        /// 
        /// The CLR type of this type
        /// The primitive type kind of the primitive type 
        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); 
            return primitiveType;
        }

 
        public override System.Collections.ObjectModel.ReadOnlyCollection GetStoreTypes()
        { 
            InitializePrimitiveTypes(); 
            return this._primitiveTypes;
        } 

        public override TypeUsage GetEdmType(TypeUsage storeType)
        {
            throw new NotImplementedException(); 
        }
 
        public override TypeUsage GetStoreType(TypeUsage edmType) 
        {
            throw new NotImplementedException(); 
        }

        /// 
        /// Providers should override this to return information specific to their provider. 
        ///
        /// This method should never return null. 
        ///  
        /// The name of the information to be retrieved.
        /// An XmlReader at the begining of the information requested. 
        protected override System.Xml.XmlReader GetDbInformation(string informationType)
        {
            throw new NotImplementedException();
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//---------------------------------------------------------------------- 
// 
//      Copyright (c) Microsoft Corporation.  All rights reserved.
// 
// 
// @owner       [....]
// @backupOwner [....] 
//--------------------------------------------------------------------- 

using System.Collections.Generic; 
using System.Data.Common;
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Threading; 
using System.Linq;
 
namespace System.Data.Metadata.Edm 
{
    internal class ClrProviderManifest : DbProviderManifest 
    {
        private const int s_PrimitiveTypeCount = 15;
        private System.Collections.ObjectModel.ReadOnlyCollection _primitiveTypes;
        private static ClrProviderManifest _instance = new ClrProviderManifest(); 

        ///  
        /// A private constructor to prevent other places from instantiating this class 
        /// 
        private ClrProviderManifest() 
        {
        }

        ///  
        /// Gets the EDM provider manifest singleton instance
        ///  
        internal static ClrProviderManifest Instance 
        {
            get 
            {
                return _instance;
            }
        } 

        ///  
        /// Returns the namespace used by this provider manifest 
        /// 
        public override string NamespaceName 
        {
            get { return EdmConstants.ClrPrimitiveTypeNamespace; }
        }
 
        /// 
        /// Returns the primitive type corresponding to the given CLR type 
        ///  
        /// The CLR type for which the PrimitiveType object is retrieved
        /// The retrieved primitive type 
        /// True if a primitive type is returned
        internal bool TryGetPrimitiveType(Type clrType, out PrimitiveType primitiveType)
        {
            primitiveType = null; 
            InitializePrimitiveTypes();
            for (int i = 0 ; i < _primitiveTypes.Count ; i++ ) 
            { 
                if (_primitiveTypes[i].ClrEquivalentType.Equals(clrType))
                { 
                    primitiveType = _primitiveTypes[i];
                    return true;
                }
            } 
            return false;
        } 
 
        /// 
        /// Returns all the functions in this provider manifest 
        /// 
        /// A collection of functions
        public override System.Collections.ObjectModel.ReadOnlyCollection GetStoreFunctions()
        { 
            return Helper.EmptyEdmFunctionReadOnlyCollection;
        } 
 
        /// 
        /// Returns all the FacetDescriptions for a particular type 
        /// 
        /// the type to return FacetDescriptions for.
        /// The FacetDescriptions for the type given.
        public override System.Collections.ObjectModel.ReadOnlyCollection GetFacetDescriptions(EdmType type) 
        {
            if (Helper.IsPrimitiveType(type) && ((PrimitiveType)type).DataSpace == DataSpace.OSpace) 
            { 
                // we don't have our own facets, just defer to the edm primitive type facets
                PrimitiveType basePrimitive = (PrimitiveType)type.BaseType; 
                return basePrimitive.ProviderManifest.GetFacetDescriptions(basePrimitive);
            }

            return Helper.EmptyFacetDescriptionEnumerable; 
        }
 
        ///  
        /// Initializes all the primitive types
        ///  
        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.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);
 
            for (int i = 0; i < primitiveTypes.Length; i++) 
            {
                primitiveTypes[i].SetReadOnly(); 
            }

            System.Collections.ObjectModel.ReadOnlyCollection readOnlyTypes = new System.Collections.ObjectModel.ReadOnlyCollection(primitiveTypes);
 
            // Set the result to _primitiveTypes at the end
            Interlocked.CompareExchange>(ref _primitiveTypes, readOnlyTypes, null); 
        } 

        ///  
        /// Initialize the primitive type with the given
        /// 
        /// The CLR type of this type
        /// The primitive type kind of the primitive type 
        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); 
            return primitiveType;
        }

 
        public override System.Collections.ObjectModel.ReadOnlyCollection GetStoreTypes()
        { 
            InitializePrimitiveTypes(); 
            return this._primitiveTypes;
        } 

        public override TypeUsage GetEdmType(TypeUsage storeType)
        {
            throw new NotImplementedException(); 
        }
 
        public override TypeUsage GetStoreType(TypeUsage edmType) 
        {
            throw new NotImplementedException(); 
        }

        /// 
        /// Providers should override this to return information specific to their provider. 
        ///
        /// This method should never return null. 
        ///  
        /// The name of the information to be retrieved.
        /// An XmlReader at the begining of the information requested. 
        protected override System.Xml.XmlReader GetDbInformation(string informationType)
        {
            throw new NotImplementedException();
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK