コード例 #1
0
        private static Facet[] CreateInitialFacets(FacetDescription[] facetDescriptions)
        {
            Facet[] facetArray = new Facet[facetDescriptions.Length];
            for (int index = 0; index < facetDescriptions.Length; ++index)
            {
                switch (facetDescriptions[index].FacetName)
                {
                case "MaxLength":
                    facetArray[index] = Facet.Create(facetDescriptions[index], (object)TypeUsage.DefaultMaxLengthFacetValue);
                    break;

                case "Unicode":
                    facetArray[index] = Facet.Create(facetDescriptions[index], (object)true);
                    break;

                case "FixedLength":
                    facetArray[index] = Facet.Create(facetDescriptions[index], (object)false);
                    break;

                case "Precision":
                    facetArray[index] = Facet.Create(facetDescriptions[index], (object)TypeUsage.DefaultPrecisionFacetValue);
                    break;

                case "Scale":
                    facetArray[index] = Facet.Create(facetDescriptions[index], (object)TypeUsage.DefaultScaleFacetValue);
                    break;
                }
            }
            return(facetArray);
        }
コード例 #2
0
        private static void PopulateGeneralFacets(
            StructuredProperty somProperty,
            ref TypeUsage propertyTypeUsage)
        {
            bool flag = false;
            Dictionary <string, Facet> dictionary = propertyTypeUsage.Facets.ToDictionary <Facet, string>((Func <Facet, string>)(f => f.Name));

            if (!somProperty.Nullable)
            {
                dictionary["Nullable"] = Facet.Create(MetadataItem.NullableFacetDescription, (object)false);
                flag = true;
            }
            if (somProperty.Default != null)
            {
                dictionary["DefaultValue"] = Facet.Create(MetadataItem.DefaultValueFacetDescription, somProperty.DefaultAsObject);
                flag = true;
            }
            if (somProperty.Schema.SchemaVersion == 1.1)
            {
                Facet facet = Facet.Create(MetadataItem.CollectionKindFacetDescription, (object)somProperty.CollectionKind);
                dictionary.Add(facet.Name, facet);
                flag = true;
            }
            if (!flag)
            {
                return;
            }
            propertyTypeUsage = TypeUsage.Create(propertyTypeUsage.EdmType, (IEnumerable <Facet>)dictionary.Values);
        }
コード例 #3
0
        private static void ApplyTypePropertyFacets(TypeUsage sourceType, ref TypeUsage targetType)
        {
            Dictionary <string, Facet> dictionary = targetType.Facets.ToDictionary <Facet, string>((Func <Facet, string>)(f => f.Name));
            bool flag = false;

            foreach (Facet facet1 in sourceType.Facets)
            {
                Facet facet2;
                if (dictionary.TryGetValue(facet1.Name, out facet2))
                {
                    if (!facet2.Description.IsConstant)
                    {
                        flag = true;
                        dictionary[facet2.Name] = Facet.Create(facet2.Description, facet1.Value);
                    }
                }
                else
                {
                    flag = true;
                    dictionary.Add(facet1.Name, facet1);
                }
            }
            if (!flag)
            {
                return;
            }
            targetType = TypeUsage.Create(targetType.EdmType, (IEnumerable <Facet>)dictionary.Values);
        }
コード例 #4
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);
 }
コード例 #5
0
 internal override void SetReadOnly()
 {
     if (!this.IsReadOnly && this.ToEndMember != null && this.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.One)
     {
         this.TypeUsage = this.TypeUsage.ShallowCopy(Facet.Create(MetadataItem.NullableFacetDescription, (object)false));
     }
     base.SetReadOnly();
 }
コード例 #6
0
        public void Can_add_new_facet_with_shallow_copy()
        {
            var typeUsage1 = TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            Assert.Equal(5, typeUsage1.Facets.Count);

            var typeUsage2 = typeUsage1.ShallowCopy(Facet.Create(Converter.ConcurrencyModeFacet, ConcurrencyMode.Fixed));

            Assert.Equal(5, typeUsage1.Facets.Count);
            Assert.Equal(6, typeUsage2.Facets.Count);
            Assert.Equal(ConcurrencyMode.Fixed, typeUsage2.Facets["ConcurrencyMode"].Value);
        }
コード例 #7
0
        internal override void SetReadOnly()
        {
            if (!IsReadOnly &&
                (ToEndMember != null) &&
                (ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.One))
            {
                // Correct our nullability if the multiplicity of the target end has changed.
                TypeUsage = TypeUsage.ShallowCopy(Facet.Create(NullableFacetDescription, false));
            }

            base.SetReadOnly();
        }
コード例 #8
0
        private static void Test_create_copies_value <T>(FacetDescription description, T value)
        {
            var facet = Facet.Create(description, value: value);

            var values = FacetValues.Create(new List <Facet> {
                facet
            });

            Facet returnedFacet = null;

            Assert.True(values.TryGetFacet(description, out returnedFacet));
            Assert.Equal(facet.Value, returnedFacet.Value);
        }
コード例 #9
0
        public void Can_update_existing_facet_with_shallow_copy()
        {
            var typeUsage1 = TypeUsage.Create(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));

            Assert.Equal(5, typeUsage1.Facets.Count);
            Assert.True((bool)typeUsage1.Facets["Nullable"].Value);

            var typeUsage2 = typeUsage1.ShallowCopy(Facet.Create(MetadataItem.NullableFacetDescription, false));

            Assert.Equal(5, typeUsage1.Facets.Count);
            Assert.Equal(5, typeUsage2.Facets.Count);
            Assert.True((bool)typeUsage1.Facets["Nullable"].Value);
            Assert.False((bool)typeUsage2.Facets["Nullable"].Value);
        }
コード例 #10
0
 private static Facet CreateConstFacet(string facetName, PrimitiveTypeKind facetTypeKind, object value)
 {
     return
         (Facet.Create(
              new FacetDescription(
                  facetName,
                  PrimitiveType.GetEdmPrimitiveType(facetTypeKind),
                  null,
                  null,
                  value,
                  true,
                  null),
              value));
 }
コード例 #11
0
        public void Create_copies_value_from_ConcurrencyModeFacet()
        {
            var description = new FacetDescription(
                EdmProviderManifest.ConcurrencyModeFacetName, new EnumType(typeof(ConcurrencyMode)), null, null, null);
            var facet = Facet.Create(description, value: ConcurrencyMode.Fixed);

            var values = FacetValues.Create(new List <Facet> {
                facet
            });

            Facet returnedFacet = null;

            Assert.True(values.TryGetFacet(description, out returnedFacet));
            Assert.Equal(facet.Value, returnedFacet.Value);
        }
コード例 #12
0
        public void Create_copies_value_from_StoreGeneratedPatternFacet()
        {
            var description = new FacetDescription(
                EdmProviderManifest.StoreGeneratedPatternFacetName, new EnumType(typeof(StoreGeneratedPattern)), null, null, null);
            var facet = Facet.Create(description, value: StoreGeneratedPattern.Computed);

            var values = FacetValues.Create(new List <Facet> {
                facet
            });

            Facet returnedFacet = null;

            Assert.True(values.TryGetFacet(description, out returnedFacet));
            Assert.Equal(facet.Value, returnedFacet.Value);
        }
コード例 #13
0
 internal Facet GetBooleanFacet(bool value)
 {
     if (this._valueCache == null)
     {
         Interlocked.CompareExchange <Facet[]>(ref this._valueCache, new Facet[2]
         {
             Facet.Create(this, (object)true, true),
             Facet.Create(this, (object)false, true)
         }, (Facet[])null);
     }
     if (!value)
     {
         return(this._valueCache[1]);
     }
     return(this._valueCache[0]);
 }
コード例 #14
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]);
        }
コード例 #15
0
        public void Create_copies_value_from_PrecisionFacet()
        {
            var description = new FacetDescription(
                DbProviderManifest.PrecisionFacetName, new PrimitiveType {
                PrimitiveTypeKind = PrimitiveTypeKind.Byte
            }, null, null, null);
            var facet = Facet.Create(description, value: (byte)1);

            var values = FacetValues.Create(new List <Facet> {
                facet
            });

            Facet returnedFacet = null;

            Assert.True(values.TryGetFacet(description, out returnedFacet));
            Assert.Equal(facet.Value, returnedFacet.Value);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        internal bool TryGetFacet(FacetDescription description, out Facet facet)
        {
            switch (description.FacetName)
            {
            case "Nullable":
                if (this._nullable.HasValue)
                {
                    facet = Facet.Create(description, this._nullable.GetValueAsObject());
                    return(true);
                }
                break;

            case "MaxLength":
                if (this._maxLength.HasValue)
                {
                    facet = Facet.Create(description, this._maxLength.GetValueAsObject());
                    return(true);
                }
                break;

            case "Unicode":
                if (this._unicode.HasValue)
                {
                    facet = Facet.Create(description, this._unicode.GetValueAsObject());
                    return(true);
                }
                break;

            case "FixedLength":
                if (this._fixedLength.HasValue)
                {
                    facet = Facet.Create(description, this._fixedLength.GetValueAsObject());
                    return(true);
                }
                break;

            case "Precision":
                if (this._precision.HasValue)
                {
                    facet = Facet.Create(description, this._precision.GetValueAsObject());
                    return(true);
                }
                break;

            case "Scale":
                if (this._scale.HasValue)
                {
                    facet = Facet.Create(description, this._scale.GetValueAsObject());
                    return(true);
                }
                break;

            case "DefaultValue":
                if (this._defaultValue != null)
                {
                    facet = Facet.Create(description, this._defaultValue);
                    return(true);
                }
                break;

            case "Collation":
                if (this._collation.HasValue)
                {
                    facet = Facet.Create(description, this._collation.GetValueAsObject());
                    return(true);
                }
                break;

            case "SRID":
                if (this._srid.HasValue)
                {
                    facet = Facet.Create(description, this._srid.GetValueAsObject());
                    return(true);
                }
                break;

            case "IsStrict":
                if (this._isStrict.HasValue)
                {
                    facet = Facet.Create(description, this._isStrict.GetValueAsObject());
                    return(true);
                }
                break;

            case "StoreGeneratedPattern":
                if (this._storeGeneratedPattern.HasValue)
                {
                    facet = Facet.Create(description, this._storeGeneratedPattern.GetValueAsObject());
                    return(true);
                }
                break;

            case "ConcurrencyMode":
                if (this._concurrencyMode.HasValue)
                {
                    facet = Facet.Create(description, this._concurrencyMode.GetValueAsObject());
                    return(true);
                }
                break;

            case "CollectionKind":
                if (this._collectionKind.HasValue)
                {
                    facet = Facet.Create(description, this._collectionKind.GetValueAsObject());
                    return(true);
                }
                break;
            }
            facet = (Facet)null;
            return(false);
        }
コード例 #18
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);
        }
コード例 #19
0
 internal static Facet Create(FacetDescription facetDescription, object value)
 {
     return(Facet.Create(facetDescription, value, false));
 }