Ejemplo n.º 1
0
 internal static bool IsUnboundedFacetValue(Facet facet)
 {
     // TODO: vamshikb
     // Use return object.ReferenceEquals(facet.Value, EdmConstants.UnboundedValue);
     // when EdmConstants.UnboundedValue is made public.
     return (null == facet.Value || facet.IsUnbounded);
 }
Ejemplo n.º 2
0
        public static void VerifyFacetsEquivalent(LegacyMetadata.Facet legacyFacet, Facet facet)
        {
            Assert.Equal(legacyFacet.Name, facet.Name);
            Assert.Equal(legacyFacet.FacetType.FullName, facet.FacetType.FullName);

            // Specialcase Variable, Max and Identity facet values - they are internal singleton objects.
            if (legacyFacet.Value != null &&
                (new[] { "Max", "Variable", "Identity" }.Contains(legacyFacet.Value.ToString()) ||
                 facet.Name == "ConcurrencyMode"))
            {
                // this is to make sure we did not stick EF6 Max/Variable/Identity on legacy facet as the value
                Assert.Equal(typeof(LegacyMetadata.EdmType).Assembly, legacyFacet.Value.GetType().Assembly);

                Assert.NotNull(facet.Value);
                Assert.Equal(legacyFacet.Value.ToString(), facet.Value.ToString());
            }
            else
            {
                Assert.Equal(legacyFacet.Value, facet.Value);
            }

            Assert.Equal(legacyFacet.IsUnbounded, facet.IsUnbounded);
            Assert.Equal(LegacyMetadata.BuiltInTypeKind.Facet, legacyFacet.BuiltInTypeKind);
            Assert.Equal(BuiltInTypeKind.Facet, facet.BuiltInTypeKind);
        }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
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)
        {
            //Contract.Requires(facetDescription != null);

            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;
        }
        /// <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];
        }
Ejemplo n.º 6
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)
        {
            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];
        }
        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;
        }
        protected override void Visit(Facet facet)
        {
            int index;
            if (facet.Name != DbProviderManifest.NullableFacetName)
            {
                // skip all the non interesting facets
                return;
            }

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

            this.AddObjectStartDumpToHashBuilder(facet, index);

            #region Inner data visit
            this.AddObjectContentToHashBuilder(facet.Identity);
            // Identity already contains Name
            this.AddObjectContentToHashBuilder(facet.Value);

            base.Visit(facet);

            #endregion

            this.AddObjectEndDumpToHashBuilder();
        }
 protected virtual void Visit(Facet facet)
 {
     Visit(facet.FacetType);
 }