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;
 }
Example #2
0
        /// <summary>
        ///     Creates a Facet instance with the specified value for the given
        ///     facet description.
        /// </summary>
        /// <param name="facetDescription"> The object describing this facet </param>
        /// <param name="value"> The value of the facet </param>
        /// <param name="bypassKnownValues"> true to bypass caching and known values; false otherwise. </param>
        /// <exception cref="System.ArgumentNullException">Thrown if facetDescription argument is null</exception>
        internal static Facet Create(FacetDescription facetDescription, object value, bool bypassKnownValues)
        {
            DebugCheck.NotNull(facetDescription);

            if (!bypassKnownValues)
            {
                // Reuse facets with a null value.
                if (ReferenceEquals(value, null))
                {
                    return facetDescription.NullValueFacet;
                }

                // Reuse facets with a default value.
                if (Equals(facetDescription.DefaultValue, value))
                {
                    return facetDescription.DefaultValueFacet;
                }

                // Special case boolean facets.
                if (facetDescription.FacetType.Identity == "Edm.Boolean")
                {
                    var boolValue = (bool)value;
                    return facetDescription.GetBooleanFacet(boolValue);
                }
            }

            var result = new Facet(facetDescription, value);

            // Check the type of the value only if we know what the correct CLR type is
            if (value != null
                && !Helper.IsUnboundedFacetValue(result)
                && !Helper.IsVariableFacetValue(result)
                && result.FacetType.ClrType != null)
            {
                var valueType = value.GetType();
                Debug.Assert(
                    valueType == result.FacetType.ClrType
                    || result.FacetType.ClrType.IsAssignableFrom(valueType),
                    string.Format(
                        CultureInfo.CurrentCulture, "The facet {0} has type {1}, but a value of type {2} was supplied.", result.Name,
                        result.FacetType.ClrType, valueType)
                    );
            }

            return result;
        }
Example #3
0
 internal static bool IsUnboundedFacetValue(Facet facet)
 {
     return (null == facet.Value || facet.IsUnbounded);
 }
 protected virtual void Visit(Facet facet)
 {
     Visit(facet.FacetType);
 }
        private static Facet[] CreateInitialFacets(FacetDescription[] facetDescriptions)
        {
            Debug.Assert(facetDescriptions != null && facetDescriptions.Length > 0);

            var facets = new Facet[facetDescriptions.Length];

            for (var 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;
        }
Example #6
0
        internal bool TryGetFacet(FacetDescription description, out Facet facet)
        {
            switch (description.FacetName)
            {
                case DbProviderManifest.NullableFacetName:
                    if (_nullable.HasValue)
                    {
                        facet = Facet.Create(description, _nullable.GetValueAsObject());
                        return true;
                    }
                    break;
                case DbProviderManifest.MaxLengthFacetName:
                    if (_maxLength.HasValue)
                    {
                        facet = Facet.Create(description, _maxLength.GetValueAsObject());
                        return true;
                    }
                    break;
                case DbProviderManifest.UnicodeFacetName:
                    if (_unicode.HasValue)
                    {
                        facet = Facet.Create(description, _unicode.GetValueAsObject());
                        return true;
                    }
                    break;
                case DbProviderManifest.FixedLengthFacetName:
                    if (_fixedLength.HasValue)
                    {
                        facet = Facet.Create(description, _fixedLength.GetValueAsObject());
                        return true;
                    }
                    break;
                case DbProviderManifest.PrecisionFacetName:
                    if (_precision.HasValue)
                    {
                        facet = Facet.Create(description, _precision.GetValueAsObject());
                        return true;
                    }
                    break;
                case DbProviderManifest.ScaleFacetName:
                    if (_scale.HasValue)
                    {
                        facet = Facet.Create(description, _scale.GetValueAsObject());
                        return true;
                    }
                    break;
                case DbProviderManifest.DefaultValueFacetName:
                    if (_defaultValue != null)
                    {
                        facet = Facet.Create(description, _defaultValue);
                        return true;
                    }
                    break;
                case DbProviderManifest.CollationFacetName:
                    if (_collation.HasValue)
                    {
                        facet = Facet.Create(description, _collation.GetValueAsObject());
                        return true;
                    }
                    break;
                case DbProviderManifest.SridFacetName:
                    if (_srid.HasValue)
                    {
                        facet = Facet.Create(description, _srid.GetValueAsObject());
                        return true;
                    }
                    break;
                case DbProviderManifest.IsStrictFacetName:
                    if (_isStrict.HasValue)
                    {
                        facet = Facet.Create(description, _isStrict.GetValueAsObject());
                        return true;
                    }
                    break;
                case EdmProviderManifest.StoreGeneratedPatternFacetName:
                    if (_storeGeneratedPattern.HasValue)
                    {
                        facet = Facet.Create(description, _storeGeneratedPattern.GetValueAsObject());
                        return true;
                    }
                    break;
                case EdmProviderManifest.ConcurrencyModeFacetName:
                    if (_concurrencyMode.HasValue)
                    {
                        facet = Facet.Create(description, _concurrencyMode.GetValueAsObject());
                        return true;
                    }
                    break;
                case EdmConstants.CollectionKind:
                    if (_collectionKind.HasValue)
                    {
                        facet = Facet.Create(description, _collectionKind.GetValueAsObject());
                        return true;
                    }
                    break;
                default:
                    Debug.Assert(false, "Unrecognized facet: " + description.FacetName);
                    break;
            }

            facet = null;
            return false;
        }
        /// <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)
        {
            Debug.Assert(FacetType.Identity == "Edm.Boolean");
            if (_valueCache == null)
            {
                var valueCache = new Facet[2];
                valueCache[0] = Facet.Create(this, true, true);
                valueCache[1] = Facet.Create(this, false, true);

                Interlocked.CompareExchange(
                    ref _valueCache,
                    valueCache,
                    null
                    );
            }
            return (value) ? _valueCache[0] : _valueCache[1];
        }
        protected override void Visit(Facet facet)
        {
            int index;
            if (facet.Name
                != DbProviderManifest.NullableFacetName)
            {
                // skip all the non interesting facets
                return;
            }

            if (!AddObjectToSeenListAndHashBuilder(facet, out index))
            {
                return;
            }

            AddObjectStartDumpToHashBuilder(facet, index);

            #region Inner data visit

            AddObjectContentToHashBuilder(facet.Identity);
            // Identity already contains Name
            AddObjectContentToHashBuilder(facet.Value);

            base.Visit(facet);

            #endregion

            AddObjectEndDumpToHashBuilder();
        }