internal bool TryGetFacet(FacetDescription description, out Facet facet)
 {
     if (description.FacetName == DbProviderManifest.NullableFacetName)
     {
         if (_nullable.HasValue)
         {
             facet = Facet.Create(description, _nullable.GetValueAsObject());
             return(true);
         }
     }
     else if (description.FacetName == DbProviderManifest.MaxLengthFacetName)
     {
         if (_maxLength.HasValue)
         {
             facet = Facet.Create(description, _maxLength.GetValueAsObject());
             return(true);
         }
     }
     else if (description.FacetName == DbProviderManifest.UnicodeFacetName)
     {
         if (_unicode.HasValue)
         {
             facet = Facet.Create(description, _unicode.GetValueAsObject());
             return(true);
         }
     }
     else if (description.FacetName == DbProviderManifest.FixedLengthFacetName)
     {
         if (_fixedLength.HasValue)
         {
             facet = Facet.Create(description, _fixedLength.GetValueAsObject());
             return(true);
         }
     }
     else if (description.FacetName == DbProviderManifest.PrecisionFacetName)
     {
         if (_precision.HasValue)
         {
             facet = Facet.Create(description, _precision.GetValueAsObject());
             return(true);
         }
     }
     else if (description.FacetName == DbProviderManifest.ScaleFacetName)
     {
         if (_scale.HasValue)
         {
             facet = Facet.Create(description, _scale.GetValueAsObject());
             return(true);
         }
     }
     facet = null;
     return(false);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a cached facet instance with the specified boolean value.
        /// </summary>
        /// <param name="value">Value for the Facet result.</param>
        /// <returns>A cached facet instance with the specified boolean value.</returns>
        internal Facet GetBooleanFacet(bool value)
        {
            System.Diagnostics.Debug.Assert(this.FacetType.Identity == "Edm.Boolean");
            if (_valueCache == null)
            {
                Facet[] valueCache = new Facet[2];
                valueCache[0] = Facet.Create(this, true, true);
                valueCache[1] = Facet.Create(this, false, true);

                System.Threading.Interlocked.CompareExchange(
                    ref _valueCache,
                    valueCache,
                    null
                    );
            }
            return((value) ? _valueCache[0] : _valueCache[1]);
        }
Exemplo n.º 3
0
        private static Facet[] CreateInitialFacets(FacetDescription[] facetDescriptions)
        {
            Debug.Assert(facetDescriptions != null && facetDescriptions.Length > 0);

            Facet[] facets = new Facet[facetDescriptions.Length];

            for (int i = 0; i < facetDescriptions.Length; ++i)
            {
                switch (facetDescriptions[i].FacetName)
                {
                case DbProviderManifest.MaxLengthFacetName:
                    facets[i] = Facet.Create(facetDescriptions[i], TypeUsage.DefaultMaxLengthFacetValue);
                    break;

                case DbProviderManifest.UnicodeFacetName:
                    facets[i] = Facet.Create(facetDescriptions[i], TypeUsage.DefaultUnicodeFacetValue);
                    break;

                case DbProviderManifest.FixedLengthFacetName:
                    facets[i] = Facet.Create(facetDescriptions[i], TypeUsage.DefaultFixedLengthFacetValue);
                    break;

                case DbProviderManifest.PrecisionFacetName:
                    facets[i] = Facet.Create(facetDescriptions[i], TypeUsage.DefaultPrecisionFacetValue);
                    break;

                case DbProviderManifest.ScaleFacetName:
                    facets[i] = Facet.Create(facetDescriptions[i], TypeUsage.DefaultScaleFacetValue);
                    break;

                default:
                    Debug.Assert(false, "Unexpected facet");
                    break;
                }
            }

            return(facets);
        }