Ejemplo n.º 1
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.º 2
0
        /// <summary>
        /// The constructor for constructing a Facet object with the facet description and a value
        /// </summary>
        /// <param name="facetDescription">The object describing this facet</param>
        /// <param name="value">The value of the facet</param>
        /// <exception cref="System.ArgumentNullException">Thrown if facetDescription argument is null</exception>
        private Facet(FacetDescription facetDescription, object value)
            : base(MetadataFlags.Readonly)
        {
            EntityUtil.GenericCheckArgumentNull(facetDescription, "facetDescription");

            _facetDescription = facetDescription;
            _value = value;
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     The constructor for constructing a Facet object with the facet description and a value
        /// </summary>
        /// <param name="facetDescription"> The object describing this facet </param>
        /// <param name="value"> The value of the facet </param>
        /// <exception cref="System.ArgumentNullException">Thrown if facetDescription argument is null</exception>
        private Facet(FacetDescription facetDescription, object value)
            : base(MetadataFlags.Readonly)
        {
            Check.NotNull(facetDescription, "facetDescription");

            _facetDescription = facetDescription;
            _value = value;
        }
Ejemplo n.º 4
0
        static Converter()
        {
            Debug.Assert(Enum.GetUnderlyingType(typeof(ConcurrencyMode)) == typeof(int), "Please update underlying type below accordingly.");

            // Create the enum types that we will need
            var concurrencyModeType = new EnumType(
                EdmProviderManifest.ConcurrencyModeFacetName,
                EdmConstants.EdmNamespace,
                underlyingType: PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32),
                isFlags: false,
                dataSpace: DataSpace.CSpace);

            foreach (var name in Enum.GetNames(typeof(ConcurrencyMode)))
            {
                concurrencyModeType.AddMember(
                    new EnumMember(
                        name,
                        (int)Enum.Parse(typeof(ConcurrencyMode), name, false)));
            }

            Debug.Assert(
                Enum.GetUnderlyingType(typeof(StoreGeneratedPattern)) == typeof(int), "Please update underlying type below accordingly.");

            var storeGeneratedPatternType = new EnumType(
                EdmProviderManifest.StoreGeneratedPatternFacetName,
                EdmConstants.EdmNamespace,
                underlyingType: PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32),
                isFlags: false,
                dataSpace: DataSpace.CSpace);

            foreach (var name in Enum.GetNames(typeof(StoreGeneratedPattern)))
            {
                storeGeneratedPatternType.AddMember(
                    new EnumMember(
                        name,
                        (int)Enum.Parse(typeof(StoreGeneratedPattern), name, false)));
            }

            // Now create the facet description objects
            ConcurrencyModeFacet = new FacetDescription(
                EdmProviderManifest.ConcurrencyModeFacetName,
                concurrencyModeType,
                null,
                null,
                ConcurrencyMode.None);
            StoreGeneratedPatternFacet = new FacetDescription(
                EdmProviderManifest.StoreGeneratedPatternFacetName,
                storeGeneratedPatternType,
                null,
                null,
                StoreGeneratedPattern.None);
            CollationFacet = new FacetDescription(
                DbProviderManifest.CollationFacetName,
                MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.String),
                null,
                null,
                string.Empty);
        }
        internal override void Configure(DbPrimitiveTypeFacets facets, FacetDescription facetDescription)
        {
            base.Configure(facets, facetDescription);

            switch (facetDescription.FacetName)
            {
                case SsdlConstants.Attribute_Precision:
                    facets.Precision = facetDescription.IsConstant ? null : Precision ?? facets.Precision;
                    break;
            }
        }
        internal override void Configure(EdmProperty column, FacetDescription facetDescription)
        {
            base.Configure(column, facetDescription);

            switch (facetDescription.FacetName)
            {
                case XmlConstants.UnicodeElement:
                    column.IsUnicode = facetDescription.IsConstant ? null : IsUnicode ?? column.IsUnicode;
                    break;
            }
        }
        internal override void Configure(DbPrimitiveTypeFacets facets, FacetDescription facetDescription)
        {
            base.Configure(facets, facetDescription);

            switch (facetDescription.FacetName)
            {
                case SsdlConstants.Attribute_Unicode:
                    facets.IsUnicode = facetDescription.IsConstant ? null : IsUnicode ?? facets.IsUnicode;
                    break;
            }
        }
        internal override void Configure(EdmProperty column, FacetDescription facetDescription)
        {
            base.Configure(column, facetDescription);

            switch (facetDescription.FacetName)
            {
                case XmlConstants.PrecisionElement:
                    column.Precision = facetDescription.IsConstant ? null : Precision ?? column.Precision;
                    break;
            }
        }
 internal override void Configure(EdmProperty column, FacetDescription facetDescription)
 {
     switch (facetDescription.FacetName)
     {
         case XmlConstants.FixedLengthElement:
             column.IsFixedLength = facetDescription.IsConstant ? null : IsFixedLength ?? column.IsFixedLength;
             break;
         case XmlConstants.MaxLengthElement:
             column.MaxLength = facetDescription.IsConstant ? null : MaxLength ?? column.MaxLength;
             column.IsMaxLength = !facetDescription.IsConstant && (IsMaxLength ?? column.IsMaxLength);
             break;
     }
 }
 internal override void Configure(DbPrimitiveTypeFacets facets, FacetDescription facetDescription)
 {
     switch (facetDescription.FacetName)
     {
         case SsdlConstants.Attribute_FixedLength:
             facets.IsFixedLength = facetDescription.IsConstant ? null : IsFixedLength ?? facets.IsFixedLength;
             break;
         case SsdlConstants.Attribute_MaxLength:
             facets.MaxLength = facetDescription.IsConstant ? null : MaxLength ?? facets.MaxLength;
             facets.IsMaxLength = facetDescription.IsConstant ? null : IsMaxLength ?? facets.IsMaxLength;
             break;
     }
 }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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;
        }
 private static void UpdateMinMaxValueForConstant(
     string facetName,
     EdmType facetType,
     ref int?minValue,
     ref int?maxValue,
     object defaultValue)
 {
     if (!FacetDescription.IsNumericType(facetType))
     {
         return;
     }
     if (facetName == "Precision" || facetName == "Scale")
     {
         ref int?local1    = ref minValue;
         byte?   nullable1 = (byte?)defaultValue;
         int?    nullable2 = nullable1.HasValue ? new int?((int)nullable1.GetValueOrDefault()) : new int?();
         local1 = nullable2;
         ref int?local2    = ref maxValue;
        static Converter()
        {
            EnumType enumType1 = new EnumType("ConcurrencyMode", "Edm", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), false, DataSpace.CSpace);

            foreach (string name in Enum.GetNames(typeof(ConcurrencyMode)))
            {
                enumType1.AddMember(new EnumMember(name, (object)(int)Enum.Parse(typeof(ConcurrencyMode), name, false)));
            }
            EnumType enumType2 = new EnumType("StoreGeneratedPattern", "Edm", PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.Int32), false, DataSpace.CSpace);

            foreach (string name in Enum.GetNames(typeof(StoreGeneratedPattern)))
            {
                enumType2.AddMember(new EnumMember(name, (object)(int)Enum.Parse(typeof(StoreGeneratedPattern), name, false)));
            }
            Converter.ConcurrencyModeFacet       = new FacetDescription("ConcurrencyMode", (EdmType)enumType1, new int?(), new int?(), (object)ConcurrencyMode.None);
            Converter.StoreGeneratedPatternFacet = new FacetDescription("StoreGeneratedPattern", (EdmType)enumType2, new int?(), new int?(), (object)StoreGeneratedPattern.None);
            Converter.CollationFacet             = new FacetDescription("Collation", (EdmType)MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.String), new int?(), new int?(), (object)string.Empty);
        }
Ejemplo n.º 18
0
 private static IEnumerable <Facet> OverrideFacetValues <T>(
     IEnumerable <T> facetThings,
     Func <T, FacetDescription> getDescription,
     Func <T, Facet> getFacet,
     FacetValues values)
 {
     foreach (T facetThing in facetThings)
     {
         FacetDescription description = getDescription(facetThing);
         Facet            facet;
         if (!description.IsConstant && values.TryGetFacet(description, out facet))
         {
             yield return(facet);
         }
         else
         {
             yield return(getFacet(facetThing));
         }
     }
 }
 internal FacetDescription(
     string facetName,
     EdmType facetType,
     int?minValue,
     int?maxValue,
     object defaultValue,
     bool isConstant,
     string declaringTypeName)
 {
     this._facetName    = facetName;
     this._facetType    = facetType;
     this._minValue     = minValue;
     this._maxValue     = maxValue;
     this._defaultValue = defaultValue == null ? FacetDescription._notInitializedSentinel : defaultValue;
     this._isConstant   = isConstant;
     this.Validate(declaringTypeName);
     if (!this._isConstant)
     {
         return;
     }
     FacetDescription.UpdateMinMaxValueForConstant(this._facetName, this._facetType, ref this._minValue, ref this._maxValue, this._defaultValue);
 }
        static MetadataItem()
        {
            MetadataItem._builtInTypes[0]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[2]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[1]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[3]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[3]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[7]  = (EdmType) new EnumType();
            MetadataItem._builtInTypes[6]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[8]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[9]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[10] = (EdmType) new EnumType();
            MetadataItem._builtInTypes[11] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[12] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[13] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[14] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[4]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[5]  = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[15] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[16] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[17] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[18] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[19] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[20] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[21] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[22] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[23] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[24] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[25] = (EdmType) new EnumType();
            MetadataItem._builtInTypes[26] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[27] = (EdmType) new EnumType();
            MetadataItem._builtInTypes[28] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[29] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[30] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[31] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[32] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[33] = (EdmType) new EnumType();
            MetadataItem._builtInTypes[34] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[35] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[36] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[37] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[38] = (EdmType) new ComplexType();
            MetadataItem._builtInTypes[39] = (EdmType) new ComplexType();
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem), "ItemType", false, (ComplexType)null);
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataProperty), "MetadataProperty", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.GlobalItem), "GlobalItem", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.TypeUsage), "TypeUsage", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType), "EdmType", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.GlobalItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.SimpleType), "SimpleType", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EnumType), "EnumType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.SimpleType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.PrimitiveType), "PrimitiveType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.SimpleType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.CollectionType), "CollectionType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.RefType), "RefType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmMember), "EdmMember", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmProperty), "EdmProperty", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmMember));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.NavigationProperty), "NavigationProperty", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmMember));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.ProviderManifest), "ProviderManifest", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.RelationshipEndMember), "RelationshipEnd", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmMember));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.AssociationEndMember), "AssociationEnd", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.RelationshipEndMember));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EnumMember), "EnumMember", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.ReferentialConstraint), "ReferentialConstraint", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.StructuralType), "StructuralType", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.RowType), "RowType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.StructuralType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.ComplexType), "ComplexType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.StructuralType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EntityTypeBase), "ElementType", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.StructuralType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EntityType), "EntityType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EntityTypeBase));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.RelationshipType), "RelationshipType", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EntityTypeBase));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.AssociationType), "AssociationType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.RelationshipType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.Facet), "Facet", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EntityContainer), "EntityContainerType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.GlobalItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EntitySetBase), "BaseEntitySetType", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EntitySet), "EntitySetType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EntitySetBase));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.RelationshipSet), "RelationshipSet", true, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EntitySetBase));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.AssociationSet), "AssocationSetType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.RelationshipSet));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.AssociationSetEnd), "AssociationSetEndType", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.FunctionParameter), "FunctionParameter", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmFunction), "EdmFunction", false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType));
            MetadataItem.InitializeBuiltInTypes((ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.Documentation), nameof(Documentation), false, (ComplexType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataItem));
            MetadataItem.InitializeEnumType(BuiltInTypeKind.OperationAction, "DeleteAction", new string[2]
            {
                "None",
                "Cascade"
            });
            MetadataItem.InitializeEnumType(BuiltInTypeKind.RelationshipMultiplicity, "RelationshipMultiplicity", new string[3]
            {
                "One",
                "ZeroToOne",
                "Many"
            });
            MetadataItem.InitializeEnumType(BuiltInTypeKind.ParameterMode, "ParameterMode", new string[3]
            {
                "In",
                "Out",
                "InOut"
            });
            MetadataItem.InitializeEnumType(BuiltInTypeKind.CollectionKind, "CollectionKind", new string[3]
            {
                "None",
                "List",
                "Bag"
            });
            MetadataItem.InitializeEnumType(BuiltInTypeKind.PrimitiveTypeKind, "PrimitiveTypeKind", Enum.GetNames(typeof(PrimitiveTypeKind)));
            FacetDescription[] facetDescriptionArray = new FacetDescription[2];
            MetadataItem._nullableFacetDescription = new FacetDescription("Nullable", (EdmType)MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean), new int?(), new int?(), (object)true);
            facetDescriptionArray[0] = MetadataItem._nullableFacetDescription;
            MetadataItem._defaultValueFacetDescription = new FacetDescription("DefaultValue", MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType), new int?(), new int?(), (object)null);
            facetDescriptionArray[1] = MetadataItem._defaultValueFacetDescription;
            MetadataItem._generalFacetDescriptions       = new ReadOnlyCollection <FacetDescription>((IList <FacetDescription>)facetDescriptionArray);
            MetadataItem._collectionKindFacetDescription = new FacetDescription("CollectionKind", MetadataItem.GetBuiltInType(BuiltInTypeKind.EnumType), new int?(), new int?(), (object)null);
            TypeUsage typeUsage1 = TypeUsage.Create((EdmType)MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.String));
            TypeUsage typeUsage2 = TypeUsage.Create((EdmType)MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean));
            TypeUsage typeUsage3 = TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType));
            TypeUsage typeUsage4 = TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.TypeUsage));
            TypeUsage typeUsage5 = TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.ComplexType));

            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.MetadataProperty, new EdmProperty[3]
            {
                new EdmProperty("Name", typeUsage1),
                new EdmProperty("TypeUsage", typeUsage4),
                new EdmProperty("Value", typeUsage5)
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.MetadataItem, new EdmProperty[2]
            {
                new EdmProperty(nameof(MetadataProperties), TypeUsage.Create((EdmType)MetadataItem.GetBuiltInType(BuiltInTypeKind.MetadataProperty).GetCollectionType())),
                new EdmProperty(nameof(Documentation), TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.Documentation)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.TypeUsage, new EdmProperty[2]
            {
                new EdmProperty("EdmType", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType))),
                new EdmProperty("Facets", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.Facet)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.EdmType, new EdmProperty[5]
            {
                new EdmProperty("Name", typeUsage1),
                new EdmProperty("Namespace", typeUsage1),
                new EdmProperty("Abstract", typeUsage2),
                new EdmProperty("Sealed", typeUsage2),
                new EdmProperty("BaseType", typeUsage5)
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.EnumType, new EdmProperty[1]
            {
                new EdmProperty("EnumMembers", typeUsage1)
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.CollectionType, new EdmProperty[1]
            {
                new EdmProperty("TypeUsage", typeUsage4)
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.RefType, new EdmProperty[1]
            {
                new EdmProperty("EntityType", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EntityType)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.EdmMember, new EdmProperty[2]
            {
                new EdmProperty("Name", typeUsage1),
                new EdmProperty("TypeUsage", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.TypeUsage)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.EdmProperty, new EdmProperty[2]
            {
                new EdmProperty("Nullable", typeUsage1),
                new EdmProperty("DefaultValue", typeUsage5)
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.NavigationProperty, new EdmProperty[2]
            {
                new EdmProperty("RelationshipTypeName", typeUsage1),
                new EdmProperty("ToEndMemberName", typeUsage1)
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.RelationshipEndMember, new EdmProperty[2]
            {
                new EdmProperty("OperationBehaviors", typeUsage5),
                new EdmProperty("RelationshipMultiplicity", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EnumType)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.EnumMember, new EdmProperty[1]
            {
                new EdmProperty("Name", typeUsage1)
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.ReferentialConstraint, new EdmProperty[4]
            {
                new EdmProperty("ToRole", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.RelationshipEndMember))),
                new EdmProperty("FromRole", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.RelationshipEndMember))),
                new EdmProperty("ToProperties", TypeUsage.Create((EdmType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmProperty).GetCollectionType())),
                new EdmProperty("FromProperties", TypeUsage.Create((EdmType)MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmProperty).GetCollectionType()))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.StructuralType, new EdmProperty[1]
            {
                new EdmProperty("Members", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmMember)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.EntityTypeBase, new EdmProperty[1]
            {
                new EdmProperty("KeyMembers", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmMember)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.Facet, new EdmProperty[3]
            {
                new EdmProperty("Name", typeUsage1),
                new EdmProperty("EdmType", typeUsage3),
                new EdmProperty("Value", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.EntityContainer, new EdmProperty[2]
            {
                new EdmProperty("Name", typeUsage1),
                new EdmProperty("EntitySets", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EntitySet)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.EntitySetBase, new EdmProperty[4]
            {
                new EdmProperty("Name", typeUsage1),
                new EdmProperty("EntityType", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EntityType))),
                new EdmProperty("Schema", typeUsage1),
                new EdmProperty("Table", typeUsage1)
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.AssociationSet, new EdmProperty[1]
            {
                new EdmProperty("AssociationSetEnds", TypeUsage.Create((EdmType)MetadataItem.GetBuiltInType(BuiltInTypeKind.AssociationSetEnd).GetCollectionType()))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.AssociationSetEnd, new EdmProperty[2]
            {
                new EdmProperty("Role", typeUsage1),
                new EdmProperty("EntitySetType", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EntitySet)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.FunctionParameter, new EdmProperty[3]
            {
                new EdmProperty("Name", typeUsage1),
                new EdmProperty("Mode", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EnumType))),
                new EdmProperty("TypeUsage", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.TypeUsage)))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.EdmFunction, new EdmProperty[4]
            {
                new EdmProperty("Name", typeUsage1),
                new EdmProperty("Namespace", typeUsage1),
                new EdmProperty("ReturnParameter", TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.FunctionParameter))),
                new EdmProperty("Parameters", TypeUsage.Create((EdmType)MetadataItem.GetBuiltInType(BuiltInTypeKind.FunctionParameter).GetCollectionType()))
            });
            MetadataItem.AddBuiltInTypeProperties(BuiltInTypeKind.Documentation, new EdmProperty[2]
            {
                new EdmProperty("Summary", typeUsage1),
                new EdmProperty("LongDescription", typeUsage1)
            });
            for (int index = 0; index < MetadataItem._builtInTypes.Length; ++index)
            {
                MetadataItem._builtInTypes[index].SetReadOnly();
            }
        }
Ejemplo n.º 21
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>
 /// <exception cref="System.ArgumentNullException">Thrown if facetDescription argument is null</exception>
 internal static Facet Create(FacetDescription facetDescription, object value)
 {
     return(Create(facetDescription, value, false));
 }
        static MetadataItem()
        {
            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Bootstrapping the builtin types
            ////////////////////////////////////////////////////////////////////////////////////////////////
            _builtInTypes[(int)BuiltInTypeKind.AssociationEndMember] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.AssociationSet]       = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.AssociationSetEnd]    = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.AssociationType]      = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.AssociationType]      = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.CollectionKind]       = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.CollectionType]       = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.ComplexType]          = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.Documentation]        = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.OperationAction]      = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.EdmType]                  = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntityContainer]          = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntitySet]                = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntityType]               = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntitySetBase]            = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntityTypeBase]           = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EnumType]                 = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EnumMember]               = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.Facet]                    = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EdmFunction]              = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.FunctionParameter]        = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.GlobalItem]               = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.MetadataProperty]         = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.NavigationProperty]       = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.MetadataItem]             = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EdmMember]                = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.ParameterMode]            = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.PrimitiveType]            = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.PrimitiveTypeKind]        = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.EdmProperty]              = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.ProviderManifest]         = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.ReferentialConstraint]    = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RefType]                  = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RelationshipEndMember]    = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RelationshipMultiplicity] = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.RelationshipSet]          = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RelationshipType]         = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RowType]                  = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.SimpleType]               = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.StructuralType]           = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.TypeUsage]                = new ComplexType();

            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Initialize item attributes for all the built-in complex types
            ////////////////////////////////////////////////////////////////////////////////////////////////

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem),
                EdmConstants.ItemType,
                false /*isAbstract*/,
                null);

            // populate the attributes for item attributes
            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataProperty),
                EdmConstants.ItemAttribute,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.GlobalItem),
                EdmConstants.GlobalItem,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.TypeUsage),
                EdmConstants.TypeUsage,
                false, /*isAbstract*/
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            //populate the attributes for the edm type
            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType),
                EdmConstants.EdmType,
                true, /*isAbstract*/
                (ComplexType)GetBuiltInType(BuiltInTypeKind.GlobalItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.SimpleType),
                EdmConstants.SimpleType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EnumType),
                EdmConstants.EnumerationType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.SimpleType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.PrimitiveType),
                EdmConstants.PrimitiveType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.SimpleType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.CollectionType),
                EdmConstants.CollectionType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RefType),
                EdmConstants.RefType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmMember),
                EdmConstants.Member,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmProperty),
                EdmConstants.Property,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmMember));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.NavigationProperty),
                EdmConstants.NavigationProperty,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmMember));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.ProviderManifest),
                EdmConstants.ProviderManifest,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipEndMember),
                EdmConstants.RelationshipEnd,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmMember));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.AssociationEndMember),
                EdmConstants.AssociationEnd,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipEndMember));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EnumMember),
                EdmConstants.EnumerationMember,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.ReferentialConstraint),
                EdmConstants.ReferentialConstraint,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            // Structural Type hierarchy
            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.StructuralType),
                EdmConstants.StructuralType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RowType),
                EdmConstants.RowType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.StructuralType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.ComplexType),
                EdmConstants.ComplexType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.StructuralType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityTypeBase),
                EdmConstants.ElementType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.StructuralType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityType),
                EdmConstants.EntityType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityTypeBase));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipType),
                EdmConstants.RelationshipType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityTypeBase));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.AssociationType),
                EdmConstants.AssociationType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.Facet),
                EdmConstants.Facet,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityContainer),
                EdmConstants.EntityContainerType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.GlobalItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntitySetBase),
                EdmConstants.BaseEntitySetType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntitySet),
                EdmConstants.EntitySetType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntitySetBase));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipSet),
                EdmConstants.RelationshipSet,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntitySetBase));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.AssociationSet),
                EdmConstants.AssociationSetType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipSet));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.AssociationSetEnd),
                EdmConstants.AssociationSetEndType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.FunctionParameter),
                EdmConstants.FunctionParameter,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmFunction),
                EdmConstants.Function,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.Documentation),
                EdmConstants.Documentation,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Initialize item attributes for all the built-in enum types
            ////////////////////////////////////////////////////////////////////////////////////////////////
            InitializeEnumType(
                BuiltInTypeKind.OperationAction,
                EdmConstants.DeleteAction,
                new[] { EdmConstants.None, EdmConstants.Cascade });

            InitializeEnumType(
                BuiltInTypeKind.RelationshipMultiplicity,
                EdmConstants.RelationshipMultiplicity,
                new[] { EdmConstants.One, EdmConstants.ZeroToOne, EdmConstants.Many });

            InitializeEnumType(
                BuiltInTypeKind.ParameterMode,
                EdmConstants.ParameterMode,
                new[] { EdmConstants.In, EdmConstants.Out, EdmConstants.InOut });

            InitializeEnumType(
                BuiltInTypeKind.CollectionKind,
                EdmConstants.CollectionKind,
                new[] { EdmConstants.NoneCollectionKind, EdmConstants.ListCollectionKind, EdmConstants.BagCollectionKind });

            InitializeEnumType(
                BuiltInTypeKind.PrimitiveTypeKind,
                EdmConstants.PrimitiveTypeKind,
                Enum.GetNames(typeof(PrimitiveTypeKind)));

            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Bootstrapping the general facet descriptions
            ////////////////////////////////////////////////////////////////////////////////////////////////

            // Other type non-specific facets
            var generalFacetDescriptions = new FacetDescription[2];

            _nullableFacetDescription = new FacetDescription(
                DbProviderManifest.NullableFacetName,
                EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean),
                null,
                null,
                true);
            generalFacetDescriptions[0]   = (_nullableFacetDescription);
            _defaultValueFacetDescription = new FacetDescription(
                DbProviderManifest.DefaultValueFacetName,
                GetBuiltInType(BuiltInTypeKind.EdmType),
                null,
                null,
                null);
            generalFacetDescriptions[1] = (_defaultValueFacetDescription);
            _generalFacetDescriptions   = new ReadOnlyCollection <FacetDescription>(generalFacetDescriptions);

            _collectionKindFacetDescription = new FacetDescription(
                EdmConstants.CollectionKind,
                GetBuiltInType(BuiltInTypeKind.EnumType),
                null,
                null,
                null);

            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Add properties for the built-in complex types
            ////////////////////////////////////////////////////////////////////////////////////////////////
            var stringTypeUsage    = TypeUsage.Create(EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.String));
            var booleanTypeUsage   = TypeUsage.Create(EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean));
            var edmTypeUsage       = TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmType));
            var typeUsageTypeUsage = TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.TypeUsage));
            var complexTypeUsage   = TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.ComplexType));

            // populate the attributes for item attributes
            AddBuiltInTypeProperties(
                BuiltInTypeKind.MetadataProperty,
                new[]
            {
                new EdmProperty(EdmConstants.Name, stringTypeUsage),
                new EdmProperty(EdmConstants.TypeUsage, typeUsageTypeUsage),
                new EdmProperty(EdmConstants.Value, complexTypeUsage)
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.MetadataItem,
                new[]
            {
                new EdmProperty(
                    EdmConstants.ItemAttributes,
                    TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.MetadataProperty).GetCollectionType())),
                new EdmProperty(EdmConstants.Documentation, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.Documentation)))
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.TypeUsage,
                new[]
            {
                new EdmProperty(EdmConstants.EdmType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmType))),
                new EdmProperty(EdmConstants.Facets, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.Facet)))
            });

            //populate the attributes for the edm type
            AddBuiltInTypeProperties(
                BuiltInTypeKind.EdmType,
                new[]
            {
                new EdmProperty(EdmConstants.Name, stringTypeUsage),
                new EdmProperty(EdmConstants.Namespace, stringTypeUsage),
                new EdmProperty(EdmConstants.Abstract, booleanTypeUsage),
                new EdmProperty(EdmConstants.Sealed, booleanTypeUsage),
                new EdmProperty(EdmConstants.BaseType, complexTypeUsage)
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EnumType,
                new[] { new EdmProperty(EdmConstants.EnumMembers, stringTypeUsage) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.CollectionType,
                new[] { new EdmProperty(EdmConstants.TypeUsage, typeUsageTypeUsage) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.RefType,
                new[] { new EdmProperty(EdmConstants.EntityType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntityType))) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EdmMember,
                new[]
            {
                new EdmProperty(EdmConstants.Name, stringTypeUsage),
                new EdmProperty(EdmConstants.TypeUsage, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.TypeUsage)))
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EdmProperty,
                new[]
            {
                new EdmProperty(EdmConstants.Nullable, stringTypeUsage),
                new EdmProperty(EdmConstants.DefaultValue, complexTypeUsage)
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.NavigationProperty,
                new[]
            {
                new EdmProperty(EdmConstants.RelationshipTypeName, stringTypeUsage),
                new EdmProperty(EdmConstants.ToEndMemberName, stringTypeUsage)
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.RelationshipEndMember,
                new[]
            {
                new EdmProperty(EdmConstants.OperationBehaviors, complexTypeUsage),
                new EdmProperty(EdmConstants.RelationshipMultiplicity, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EnumType)))
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EnumMember,
                new[] { new EdmProperty(EdmConstants.Name, stringTypeUsage) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.ReferentialConstraint,
                new[]
            {
                new EdmProperty(EdmConstants.ToRole, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.RelationshipEndMember))),
                new EdmProperty(EdmConstants.FromRole, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.RelationshipEndMember))),
                new EdmProperty(
                    EdmConstants.ToProperties, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmProperty).GetCollectionType())),
                new EdmProperty(
                    EdmConstants.FromProperties, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmProperty).GetCollectionType()))
            });

            // Structural Type hierarchy
            AddBuiltInTypeProperties(
                BuiltInTypeKind.StructuralType,
                new[] { new EdmProperty(EdmConstants.Members, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmMember))) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EntityTypeBase,
                new[] { new EdmProperty(EdmConstants.KeyMembers, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmMember))) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.Facet,
                new[]
            {
                new EdmProperty(EdmConstants.Name, stringTypeUsage),
                new EdmProperty(EdmConstants.EdmType, edmTypeUsage),
                new EdmProperty(EdmConstants.Value, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmType)))
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EntityContainer,
                new[]
            {
                new EdmProperty(EdmConstants.Name, stringTypeUsage),
                new EdmProperty(EdmConstants.EntitySets, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntitySet)))
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EntitySetBase,
                new[]
            {
                new EdmProperty(EdmConstants.Name, stringTypeUsage),
                new EdmProperty(EdmConstants.EntityType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntityType))),
                new EdmProperty(EdmConstants.Schema, stringTypeUsage),
                new EdmProperty(EdmConstants.Table, stringTypeUsage)
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.AssociationSet,
                new[]
            {
                new EdmProperty(
                    EdmConstants.AssociationSetEnds,
                    TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.AssociationSetEnd).GetCollectionType()))
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.AssociationSetEnd,
                new[]
            {
                new EdmProperty(EdmConstants.Role, stringTypeUsage),
                new EdmProperty(EdmConstants.EntitySetType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntitySet)))
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.FunctionParameter,
                new[]
            {
                new EdmProperty(EdmConstants.Name, stringTypeUsage),
                new EdmProperty(EdmConstants.Mode, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EnumType))),
                new EdmProperty(EdmConstants.TypeUsage, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.TypeUsage)))
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EdmFunction,
                new[]
            {
                new EdmProperty(EdmConstants.Name, stringTypeUsage),
                new EdmProperty(EdmConstants.Namespace, stringTypeUsage),
                new EdmProperty(EdmConstants.ReturnParameter, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.FunctionParameter))),
                new EdmProperty(
                    EdmConstants.Parameters, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.FunctionParameter).GetCollectionType()))
            });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.Documentation,
                new[]
            {
                new EdmProperty(EdmConstants.Summary, stringTypeUsage),
                new EdmProperty(EdmConstants.LongDescription, stringTypeUsage)
            });

            // Set all types to be readonly, used SetReadOnly to skip validation method to
            for (var i = 0; i < _builtInTypes.Length; i++)
            {
                _builtInTypes[i].SetReadOnly();
            }
        }
        static MetadataItem()
        {
            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Bootstrapping the builtin types
            ////////////////////////////////////////////////////////////////////////////////////////////////
            _builtInTypes[(int)BuiltInTypeKind.AssociationEndMember] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.AssociationSet] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.AssociationSetEnd] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.AssociationType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.AssociationType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.CollectionKind] = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.CollectionType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.ComplexType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.Documentation] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.OperationAction] = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.EdmType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntityContainer] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntitySet] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntityType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntitySetBase] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EntityTypeBase] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EnumType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EnumMember] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.Facet] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EdmFunction] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.FunctionParameter] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.GlobalItem] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.MetadataProperty] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.NavigationProperty] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.MetadataItem] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.EdmMember] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.ParameterMode] = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.PrimitiveType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.PrimitiveTypeKind] = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.EdmProperty] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.ProviderManifest] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.ReferentialConstraint] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RefType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RelationshipEndMember] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RelationshipMultiplicity] = new EnumType();
            _builtInTypes[(int)BuiltInTypeKind.RelationshipSet] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RelationshipType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.RowType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.SimpleType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.StructuralType] = new ComplexType();
            _builtInTypes[(int)BuiltInTypeKind.TypeUsage] = new ComplexType();

            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Initialize item attributes for all the built-in complex types
            ////////////////////////////////////////////////////////////////////////////////////////////////

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem),
                EdmConstants.ItemType,
                false /*isAbstract*/,
                null);

            // populate the attributes for item attributes
            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataProperty),
                EdmConstants.ItemAttribute,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.GlobalItem),
                EdmConstants.GlobalItem,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.TypeUsage),
                EdmConstants.TypeUsage,
                false, /*isAbstract*/
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            //populate the attributes for the edm type
            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType),
                EdmConstants.EdmType,
                true, /*isAbstract*/
                (ComplexType)GetBuiltInType(BuiltInTypeKind.GlobalItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.SimpleType),
                EdmConstants.SimpleType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EnumType),
                EdmConstants.EnumerationType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.SimpleType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.PrimitiveType),
                EdmConstants.PrimitiveType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.SimpleType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.CollectionType),
                EdmConstants.CollectionType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RefType),
                EdmConstants.RefType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmMember),
                EdmConstants.Member,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmProperty),
                EdmConstants.Property,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmMember));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.NavigationProperty),
                EdmConstants.NavigationProperty,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmMember));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.ProviderManifest),
                EdmConstants.ProviderManifest,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipEndMember),
                EdmConstants.RelationshipEnd,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmMember));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.AssociationEndMember),
                EdmConstants.AssociationEnd,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipEndMember));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EnumMember),
                EdmConstants.EnumerationMember,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.ReferentialConstraint),
                EdmConstants.ReferentialConstraint,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            // Structural Type hierarchy
            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.StructuralType),
                EdmConstants.StructuralType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RowType),
                EdmConstants.RowType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.StructuralType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.ComplexType),
                EdmConstants.ComplexType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.StructuralType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityTypeBase),
                EdmConstants.ElementType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.StructuralType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityType),
                EdmConstants.EntityType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityTypeBase));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipType),
                EdmConstants.RelationshipType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityTypeBase));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.AssociationType),
                EdmConstants.AssociationType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.Facet),
                EdmConstants.Facet,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntityContainer),
                EdmConstants.EntityContainerType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.GlobalItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntitySetBase),
                EdmConstants.BaseEntitySetType,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntitySet),
                EdmConstants.EntitySetType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntitySetBase));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipSet),
                EdmConstants.RelationshipSet,
                true /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EntitySetBase));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.AssociationSet),
                EdmConstants.AssociationSetType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.RelationshipSet));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.AssociationSetEnd),
                EdmConstants.AssociationSetEndType,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.FunctionParameter),
                EdmConstants.FunctionParameter,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmFunction),
                EdmConstants.Function,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.EdmType));

            InitializeBuiltInTypes(
                (ComplexType)GetBuiltInType(BuiltInTypeKind.Documentation),
                EdmConstants.Documentation,
                false /*isAbstract*/,
                (ComplexType)GetBuiltInType(BuiltInTypeKind.MetadataItem));

            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Initialize item attributes for all the built-in enum types
            ////////////////////////////////////////////////////////////////////////////////////////////////
            InitializeEnumType(
                BuiltInTypeKind.OperationAction,
                EdmConstants.DeleteAction,
                new[] { EdmConstants.None, EdmConstants.Cascade, EdmConstants.Restrict });

            InitializeEnumType(
                BuiltInTypeKind.RelationshipMultiplicity,
                EdmConstants.RelationshipMultiplicity,
                new[] { EdmConstants.One, EdmConstants.ZeroToOne, EdmConstants.Many });

            InitializeEnumType(
                BuiltInTypeKind.ParameterMode,
                EdmConstants.ParameterMode,
                new[] { EdmConstants.In, EdmConstants.Out, EdmConstants.InOut });

            InitializeEnumType(
                BuiltInTypeKind.CollectionKind,
                EdmConstants.CollectionKind,
                new[] { EdmConstants.NoneCollectionKind, EdmConstants.ListCollectionKind, EdmConstants.BagCollectionKind });

            InitializeEnumType(
                BuiltInTypeKind.PrimitiveTypeKind,
                EdmConstants.PrimitiveTypeKind,
                Enum.GetNames(typeof(PrimitiveTypeKind)));

            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Bootstrapping the general facet descriptions
            ////////////////////////////////////////////////////////////////////////////////////////////////

            // Other type non-specific facets
            var generalFacetDescriptions = new FacetDescription[2];

            _nullableFacetDescription = new FacetDescription(
                DbProviderManifest.NullableFacetName,
                EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean),
                null,
                null,
                true);
            generalFacetDescriptions[0] = (_nullableFacetDescription);
            _defaultValueFacetDescription = new FacetDescription(
                DbProviderManifest.DefaultValueFacetName,
                GetBuiltInType(BuiltInTypeKind.EdmType),
                null,
                null,
                null);
            generalFacetDescriptions[1] = (_defaultValueFacetDescription);
            _generalFacetDescriptions = Array.AsReadOnly(generalFacetDescriptions);

            _collectionKindFacetDescription = new FacetDescription(
                XmlConstants.CollectionKind,
                GetBuiltInType(BuiltInTypeKind.EnumType),
                null,
                null,
                null);

            ////////////////////////////////////////////////////////////////////////////////////////////////
            // Add properties for the built-in complex types
            ////////////////////////////////////////////////////////////////////////////////////////////////
            var stringTypeUsage = TypeUsage.Create(EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.String));
            var booleanTypeUsage = TypeUsage.Create(EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean));
            var edmTypeUsage = TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmType));
            var typeUsageTypeUsage = TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.TypeUsage));
            var complexTypeUsage = TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.ComplexType));

            // populate the attributes for item attributes
            AddBuiltInTypeProperties(
                BuiltInTypeKind.MetadataProperty,
                new[]
                    {
                        new EdmProperty(EdmConstants.Name, stringTypeUsage),
                        new EdmProperty(EdmConstants.TypeUsage, typeUsageTypeUsage),
                        new EdmProperty(EdmConstants.Value, complexTypeUsage)
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.MetadataItem,
                new[]
                    {
                        new EdmProperty(
                            EdmConstants.ItemAttributes,
                            TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.MetadataProperty).GetCollectionType())),
                        new EdmProperty(EdmConstants.Documentation, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.Documentation)))
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.TypeUsage,
                new[]
                    {
                        new EdmProperty(EdmConstants.EdmType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmType))),
                        new EdmProperty(EdmConstants.Facets, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.Facet)))
                    });

            //populate the attributes for the edm type
            AddBuiltInTypeProperties(
                BuiltInTypeKind.EdmType,
                new[]
                    {
                        new EdmProperty(EdmConstants.Name, stringTypeUsage),
                        new EdmProperty(EdmConstants.Namespace, stringTypeUsage),
                        new EdmProperty(EdmConstants.Abstract, booleanTypeUsage),
                        new EdmProperty(EdmConstants.Sealed, booleanTypeUsage),
                        new EdmProperty(EdmConstants.BaseType, complexTypeUsage)
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EnumType,
                new[] { new EdmProperty(EdmConstants.EnumMembers, stringTypeUsage) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.CollectionType,
                new[] { new EdmProperty(EdmConstants.TypeUsage, typeUsageTypeUsage) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.RefType,
                new[] { new EdmProperty(EdmConstants.EntityType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntityType))) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EdmMember,
                new[]
                    {
                        new EdmProperty(EdmConstants.Name, stringTypeUsage),
                        new EdmProperty(EdmConstants.TypeUsage, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.TypeUsage)))
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EdmProperty,
                new[]
                    {
                        new EdmProperty(EdmConstants.Nullable, stringTypeUsage),
                        new EdmProperty(EdmConstants.DefaultValue, complexTypeUsage)
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.NavigationProperty,
                new[]
                    {
                        new EdmProperty(EdmConstants.RelationshipTypeName, stringTypeUsage),
                        new EdmProperty(EdmConstants.ToEndMemberName, stringTypeUsage)
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.RelationshipEndMember,
                new[]
                    {
                        new EdmProperty(EdmConstants.OperationBehaviors, complexTypeUsage),
                        new EdmProperty(EdmConstants.RelationshipMultiplicity, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EnumType)))
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EnumMember,
                new[] { new EdmProperty(EdmConstants.Name, stringTypeUsage) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.ReferentialConstraint,
                new[]
                    {
                        new EdmProperty(EdmConstants.ToRole, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.RelationshipEndMember))),
                        new EdmProperty(EdmConstants.FromRole, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.RelationshipEndMember))),
                        new EdmProperty(
                            EdmConstants.ToProperties, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmProperty).GetCollectionType())),
                        new EdmProperty(
                            EdmConstants.FromProperties, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmProperty).GetCollectionType()))
                    });

            // Structural Type hierarchy
            AddBuiltInTypeProperties(
                BuiltInTypeKind.StructuralType,
                new[] { new EdmProperty(EdmConstants.Members, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmMember))) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EntityTypeBase,
                new[] { new EdmProperty(EdmConstants.KeyMembers, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmMember))) });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.Facet,
                new[]
                    {
                        new EdmProperty(EdmConstants.Name, stringTypeUsage),
                        new EdmProperty(EdmConstants.EdmType, edmTypeUsage),
                        new EdmProperty(EdmConstants.Value, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmType)))
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EntityContainer,
                new[]
                    {
                        new EdmProperty(EdmConstants.Name, stringTypeUsage),
                        new EdmProperty(EdmConstants.EntitySets, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntitySet)))
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EntitySetBase,
                new[]
                    {
                        new EdmProperty(EdmConstants.Name, stringTypeUsage),
                        new EdmProperty(EdmConstants.EntityType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntityType))),
                        new EdmProperty(EdmConstants.Schema, stringTypeUsage),
                        new EdmProperty(EdmConstants.Table, stringTypeUsage)
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.AssociationSet,
                new[]
                    {
                        new EdmProperty(
                            EdmConstants.AssociationSetEnds,
                            TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.AssociationSetEnd).GetCollectionType()))
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.AssociationSetEnd,
                new[]
                    {
                        new EdmProperty(EdmConstants.Role, stringTypeUsage),
                        new EdmProperty(EdmConstants.EntitySetType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntitySet)))
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.FunctionParameter,
                new[]
                    {
                        new EdmProperty(EdmConstants.Name, stringTypeUsage),
                        new EdmProperty(EdmConstants.Mode, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EnumType))),
                        new EdmProperty(EdmConstants.TypeUsage, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.TypeUsage)))
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.EdmFunction,
                new[]
                    {
                        new EdmProperty(EdmConstants.Name, stringTypeUsage),
                        new EdmProperty(EdmConstants.Namespace, stringTypeUsage),
                        new EdmProperty(EdmConstants.ReturnParameter, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.FunctionParameter))),
                        new EdmProperty(
                            EdmConstants.Parameters, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.FunctionParameter).GetCollectionType()))
                    });

            AddBuiltInTypeProperties(
                BuiltInTypeKind.Documentation,
                new[]
                    {
                        new EdmProperty(EdmConstants.Summary, stringTypeUsage),
                        new EdmProperty(EdmConstants.LongDescription, stringTypeUsage)
                    });

            // Set all types to be readonly, used SetReadOnly to skip validation method to 
            for (var i = 0; i < _builtInTypes.Length; i++)
            {
                _builtInTypes[i].SetReadOnly();
            }
        }
        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);
        }
Ejemplo n.º 25
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;
        }
 internal void CreateAndValidateFacetDescription(string declaringTypeName)
 {
     _facetDescription = new FacetDescription(Name, FacetType, MinValue, MaxValue, DefaultValue, _isConstant, declaringTypeName);
 }
Ejemplo n.º 27
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;
        }
Ejemplo n.º 28
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>
 /// <exception cref="System.ArgumentNullException">Thrown if facetDescription argument is null</exception>
 internal static Facet Create(FacetDescription facetDescription, object value)
 {
     return Create(facetDescription, value, false);
 }
Ejemplo n.º 29
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);
        }
Ejemplo n.º 30
0
        internal static FacetDescription[] GetInitialFacetDescriptions(PrimitiveTypeKind primitiveTypeKind)
        {
            FacetDescription[] list;

            switch (primitiveTypeKind)
            {
                case PrimitiveTypeKind.String:
                    {
                        list = new FacetDescription[3];

                        list[0] = (new FacetDescription(
                            MaxLengthFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Int32),
                            0,
                            Int32.MaxValue,
                            null));
                        list[1] = (new FacetDescription(
                            UnicodeFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean),
                            null,
                            null,
                            null));
                        list[2] = (new FacetDescription(
                            FixedLengthFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean),
                            null,
                            null,
                            null));

                        return list;
                    }

                case PrimitiveTypeKind.Binary:
                    {
                        list = new FacetDescription[2];

                        list[0] = (new FacetDescription(
                            MaxLengthFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Int32),
                            0,
                            Int32.MaxValue,
                            null));
                        list[1] = (new FacetDescription(
                            FixedLengthFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean),
                            null,
                            null,
                            null));
                        return list;
                    }

                case PrimitiveTypeKind.DateTime:
                    {
                        list = new FacetDescription[1];

                        list[0] = (new FacetDescription(
                            PrecisionFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte),
                            0, MaximumDateTimePrecision, null));

                        return list;
                    }
                case PrimitiveTypeKind.Time:
                    {
                        list = new FacetDescription[1];

                        list[0] = (new FacetDescription(
                            PrecisionFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte),
                            0, MaximumDateTimePrecision, TypeUsage.DefaultDateTimePrecisionFacetValue));

                        return list;
                    }
                case PrimitiveTypeKind.DateTimeOffset:
                    {
                        list = new FacetDescription[1];
                        list[0] = (new FacetDescription(
                            PrecisionFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte),
                            0, MaximumDateTimePrecision, TypeUsage.DefaultDateTimePrecisionFacetValue));

                        return list;
                    }
                case PrimitiveTypeKind.Decimal:
                    {
                        list = new FacetDescription[2];

                        list[0] = (new FacetDescription(
                            PrecisionFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte),
                            1,
                            MaximumDecimalPrecision,
                            null));
                        list[1] = (new FacetDescription(
                            ScaleFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Byte),
                            0,
                            MaximumDecimalPrecision,
                            null));
                        return list;
                    }
                case PrimitiveTypeKind.Geometry:
                case PrimitiveTypeKind.GeometryPoint:
                case PrimitiveTypeKind.GeometryLineString:
                case PrimitiveTypeKind.GeometryPolygon:
                case PrimitiveTypeKind.GeometryMultiPoint:
                case PrimitiveTypeKind.GeometryMultiLineString:
                case PrimitiveTypeKind.GeometryMultiPolygon:
                case PrimitiveTypeKind.GeometryCollection:
                    {
                        list = new FacetDescription[2];

                        list[0] = (new FacetDescription(
                            SridFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Int32),
                            0,
                            Int32.MaxValue,
                            DbGeometry.DefaultCoordinateSystemId));
                        list[1] = (new FacetDescription(
                            IsStrictFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean),
                            null,
                            null,
                            true));
                        return list;
                    }
                case PrimitiveTypeKind.Geography:
                case PrimitiveTypeKind.GeographyPoint:
                case PrimitiveTypeKind.GeographyLineString:
                case PrimitiveTypeKind.GeographyPolygon:
                case PrimitiveTypeKind.GeographyMultiPoint:
                case PrimitiveTypeKind.GeographyMultiLineString:
                case PrimitiveTypeKind.GeographyMultiPolygon:
                case PrimitiveTypeKind.GeographyCollection:
                    {
                        list = new FacetDescription[2];

                        list[0] = (new FacetDescription(
                            SridFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Int32),
                            0,
                            Int32.MaxValue,
                            DbGeography.DefaultCoordinateSystemId));
                        list[1] = (new FacetDescription(
                            IsStrictFacetName,
                            MetadataItem.EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean),
                            null,
                            null,
                            true));
                        return list;
                    }
                default:
                    return null;
            }
        }