/// <summary> /// Static Constructor which initializes all the built in types and primitive types /// </summary> 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 string[] { EdmConstants.None, EdmConstants.Cascade, EdmConstants.Restrict }); InitializeEnumType(BuiltInTypeKind.RelationshipMultiplicity, EdmConstants.RelationshipMultiplicity, new string[] { EdmConstants.One, EdmConstants.ZeroToOne, EdmConstants.Many }); InitializeEnumType(BuiltInTypeKind.ParameterMode, EdmConstants.ParameterMode, new string[] { EdmConstants.In, EdmConstants.Out, EdmConstants.InOut }); InitializeEnumType(BuiltInTypeKind.CollectionKind, EdmConstants.CollectionKind, new string[] { 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 FacetDescription[] generalFacetDescriptions = new FacetDescription[2]; _nullableFacetDescription = new FacetDescription(DbProviderManifest.NullableFacetName, EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean), null, null, true); generalFacetDescriptions[0] = (_nullableFacetDescription); _defaultValueFacetDescription = new FacetDescription(DbProviderManifest.DefaultValueFacetName, MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType), null, null, null); generalFacetDescriptions[1] = (_defaultValueFacetDescription); _generalFacetDescriptions = Array.AsReadOnly(generalFacetDescriptions); _collectionKindFacetDescription = new FacetDescription(XmlConstants.CollectionKind, MetadataItem.GetBuiltInType(BuiltInTypeKind.EnumType), null, null, null); //////////////////////////////////////////////////////////////////////////////////////////////// // Add properties for the built-in complex types //////////////////////////////////////////////////////////////////////////////////////////////// TypeUsage stringTypeUsage = TypeUsage.Create(EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.String)); TypeUsage booleanTypeUsage = TypeUsage.Create(EdmProviderManifest.GetPrimitiveType(PrimitiveTypeKind.Boolean)); TypeUsage edmTypeUsage = TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.EdmType)); TypeUsage typeUsageTypeUsage = TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.TypeUsage)); TypeUsage complexTypeUsage = TypeUsage.Create(MetadataItem.GetBuiltInType(BuiltInTypeKind.ComplexType)); // populate the attributes for item attributes AddBuiltInTypeProperties(BuiltInTypeKind.MetadataProperty, new EdmProperty[] { new EdmProperty(EdmConstants.Name, stringTypeUsage), new EdmProperty(EdmConstants.TypeUsage, typeUsageTypeUsage), new EdmProperty(EdmConstants.Value, complexTypeUsage) }); AddBuiltInTypeProperties(BuiltInTypeKind.MetadataItem, new EdmProperty[] { new EdmProperty(EdmConstants.ItemAttributes, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.MetadataProperty).GetCollectionType())), new EdmProperty(EdmConstants.Documentation, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.Documentation))) }); AddBuiltInTypeProperties(BuiltInTypeKind.TypeUsage, new EdmProperty[] { 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 EdmProperty[] { 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 EdmProperty[] { new EdmProperty(EdmConstants.EnumMembers, stringTypeUsage) }); AddBuiltInTypeProperties(BuiltInTypeKind.CollectionType, new EdmProperty[] { new EdmProperty(EdmConstants.TypeUsage, typeUsageTypeUsage) }); AddBuiltInTypeProperties(BuiltInTypeKind.RefType, new EdmProperty[] { new EdmProperty(EdmConstants.EntityType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntityType))) }); AddBuiltInTypeProperties(BuiltInTypeKind.EdmMember, new EdmProperty[] { new EdmProperty(EdmConstants.Name, stringTypeUsage), new EdmProperty(EdmConstants.TypeUsage, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.TypeUsage))) }); AddBuiltInTypeProperties(BuiltInTypeKind.EdmProperty, new EdmProperty[] { new EdmProperty(EdmConstants.Nullable, stringTypeUsage), new EdmProperty(EdmConstants.DefaultValue, complexTypeUsage) }); AddBuiltInTypeProperties(BuiltInTypeKind.NavigationProperty, new EdmProperty[] { new EdmProperty(EdmConstants.RelationshipTypeName, stringTypeUsage), new EdmProperty(EdmConstants.ToEndMemberName, stringTypeUsage) }); AddBuiltInTypeProperties(BuiltInTypeKind.RelationshipEndMember, new EdmProperty[] { new EdmProperty(EdmConstants.OperationBehaviors, complexTypeUsage), new EdmProperty(EdmConstants.RelationshipMultiplicity, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EnumType))) }); AddBuiltInTypeProperties(BuiltInTypeKind.EnumMember, new EdmProperty[] { new EdmProperty(EdmConstants.Name, stringTypeUsage) }); AddBuiltInTypeProperties(BuiltInTypeKind.ReferentialConstraint, new EdmProperty[] { 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 EdmProperty[] { new EdmProperty(EdmConstants.Members, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmMember))) }); AddBuiltInTypeProperties(BuiltInTypeKind.EntityTypeBase, new EdmProperty[] { new EdmProperty(EdmConstants.KeyMembers, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmMember))) }); AddBuiltInTypeProperties(BuiltInTypeKind.Facet, new EdmProperty[] { new EdmProperty(EdmConstants.Name, stringTypeUsage), new EdmProperty(EdmConstants.EdmType, edmTypeUsage), new EdmProperty(EdmConstants.Value, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EdmType))) }); AddBuiltInTypeProperties(BuiltInTypeKind.EntityContainer, new EdmProperty[] { new EdmProperty(EdmConstants.Name, stringTypeUsage), new EdmProperty(EdmConstants.EntitySets, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntitySet))) }); AddBuiltInTypeProperties(BuiltInTypeKind.EntitySetBase, new EdmProperty[] { 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 EdmProperty[] { new EdmProperty(EdmConstants.AssociationSetEnds, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.AssociationSetEnd).GetCollectionType())) }); AddBuiltInTypeProperties(BuiltInTypeKind.AssociationSetEnd, new EdmProperty[] { new EdmProperty(EdmConstants.Role, stringTypeUsage), new EdmProperty(EdmConstants.EntitySetType, TypeUsage.Create(GetBuiltInType(BuiltInTypeKind.EntitySet))) }); AddBuiltInTypeProperties(BuiltInTypeKind.FunctionParameter, new EdmProperty[] { 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 EdmProperty[] { 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 EdmProperty[] { new EdmProperty(EdmConstants.Summary, stringTypeUsage), new EdmProperty(EdmConstants.LongDescription, stringTypeUsage) }); // Set all types to be readonly, used SetReadOnly to skip validation method to for (int i = 0; i < _builtInTypes.Length; i++) { _builtInTypes[i].SetReadOnly(); } }
/// <summary> /// Initializes a new attribute with built in type kind /// </summary> /// <param name="builtInTypeKind">Built in type setting Type property</param> /// <param name="isCollectionType">Sets IsCollectionType property</param> internal MetadataPropertyAttribute(BuiltInTypeKind builtInTypeKind, bool isCollectionType) : this(MetadataItem.GetBuiltInType(builtInTypeKind), isCollectionType) { }