internal MetadataPropertyValue(PropertyInfo propertyInfo, MetadataItem item)
 {
     Debug.Assert(null != propertyInfo);
     Debug.Assert(null != item);
     _propertyInfo = propertyInfo;
     _item = item;
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="propertySource">The event source</param>
 /// <param name="backingFieldName">The name of the field corresponding to the property</param>
 /// <param name="returnType">The property return type</param>
 public PropertyGeneratedEventArgs(MetadataItem propertySource, 
                                   string backingFieldName,
                                   CodeTypeReference returnType)
 {
     this._propertySource = propertySource;
     this._backingFieldName = backingFieldName;
     this._returnType = returnType;
 }
Beispiel #3
0
 /// <summary>
 /// Throws an appropriate exception if the given item is a readonly, used when an attempt is made to change
 /// a property
 /// </summary>
 /// <param name="item">The item whose readonly is being tested</param>
 internal static void ThrowIfReadOnly(MetadataItem item)
 {
     Debug.Assert(item != null, "The given item is null");
     if (item.IsReadOnly)
     {
         throw new InvalidOperationException(Strings.OperationOnReadOnlyItem);
     }
 }
Beispiel #4
0
 /// <summary>
 /// Throws an appropriate exception if the given item is a readonly, used when an attempt is made to change
 /// a property
 /// </summary>
 /// <param name="item">The item whose readonly is being tested</param>
 internal static void ThrowIfReadOnly(MetadataItem item)
 {
     Debug.Assert(item != null, "The given item is null");
     if (item.IsReadOnly)
     {
         throw EntityUtil.OperationOnReadOnlyItem();
     }
 }
 public static bool TryGetStringMetadataPropertySetting(MetadataItem item, string propertyName, out string value)
 {
     value = null;
     MetadataProperty property = item.MetadataProperties.FirstOrDefault(p => p.Name == propertyName);
     if (property != null)
     {
         value = (string)property.Value;
     }
     return value != null;
 }
Beispiel #6
0
        /// <summary>
        /// emit all the documentation comments for an element's documentation child
        /// (if the element does not have a documentation child emit some standard "missing comments" comment
        /// </summary>
        /// <param name="element">the element whose documentation is to be displayed</param>
        /// <param name="commentCollection">the comment collection of the CodeDom object to be commented</param>
        public static void EmitSummaryComments(MetadataItem item, CodeCommentStatementCollection commentCollection)
        {
            Debug.Assert(item != null, "item parameter is null");
            Debug.Assert(commentCollection != null, "commentCollection parameter is null");

            Documentation documentation = GetDocumentation(item);
            string [] summaryComments = null;
            if (documentation != null && !MetadataUtil.IsNullOrEmptyOrWhiteSpace(documentation.Summary)) 
            {
                // we have documentation to emit
                summaryComments = GetFormattedLines(documentation.Summary, true);
            }
            else
            {
                string summaryComment;
                // no summary content, so use a default
                switch (item.BuiltInTypeKind)
                {
                    case BuiltInTypeKind.EdmProperty:
                        summaryComment = Strings.MissingPropertyDocumentation(((EdmProperty)item).Name);
                        break;
                    case BuiltInTypeKind.ComplexType:
                        summaryComment = Strings.MissingComplexTypeDocumentation(((ComplexType)item).FullName);
                        break;
                    default:
                        {
                            PropertyInfo pi = item.GetType().GetProperty("FullName");
                            if (pi == null)
                            {
                                pi = item.GetType().GetProperty("Name");
                            }

                            object value = null;
                            if (pi != null)
                            {
                                value = pi.GetValue(item, null);
                            }


                            if (value != null)
                            {
                                summaryComment = Strings.MissingDocumentation(value.ToString());
                            }
                            else
                            {
                                summaryComment = Strings.MissingDocumentationNoName;
                            }
                        }
                        break;
                }
                summaryComments = new string[] { summaryComment };
            }
            EmitSummaryComments(summaryComments, commentCollection);
            EmitOtherDocumentationComments(documentation, commentCollection);
        }
Beispiel #7
0
        /// <summary>
        /// Finds the extended property from a collection of extended EFx properties
        /// </summary>
        /// <param name="metadataItem">MetadataItem that contains the properties to search</param>
        /// <param name="propertyName">Name of the extended property</param>
        /// <returns>The corresponding MetadataProperty object if found, null otherwise</returns>
        internal static MetadataProperty FindExtendedProperty(MetadataItem metadataItem, String propertyName)
        {
            // MetadataItem.MetadataProperties can contain at most one property with the specified name
            string extendedPropertyName = Microsoft.OData.Service.XmlConstants.DataWebMetadataNamespace + ":" + propertyName;
            MetadataProperty metadataProperty;
            if (metadataItem.MetadataProperties.TryGetValue(extendedPropertyName, false, out metadataProperty))
            {
                Debug.Assert(metadataProperty.PropertyKind == PropertyKind.Extended, "Metadata properties in the data services namespace should always be extended EDM properties");
                return metadataProperty;
            }

            return null;
        }
        /// <summary>
        /// Override EdmEquals to support value comparison of TypeUsage property
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        internal override bool EdmEquals(MetadataItem item)
        {
            // short-circuit if this and other are reference equivalent
            if (Object.ReferenceEquals(this, item))
            {
                return(true);
            }

            // check type of item
            if (null == item || BuiltInTypeKind.CollectionType != item.BuiltInTypeKind)
            {
                return(false);
            }
            CollectionType other = (CollectionType)item;

            // compare type usage
            return(this.TypeUsage.EdmEquals(other.TypeUsage));
        }
Beispiel #9
0
        /// <summary>
        /// EdmEquals override verifying the equivalence of all members and their type usages.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        internal override bool EdmEquals(MetadataItem item)
        {
            // short-circuit if this and other are reference equivalent
            if (Object.ReferenceEquals(this, item))
            {
                return(true);
            }

            // check type of item
            if (null == item || BuiltInTypeKind.RowType != item.BuiltInTypeKind)
            {
                return(false);
            }
            RowType other = (RowType)item;

            // check each row type has the same number of members
            if (this.Members.Count != other.Members.Count)
            {
                return(false);
            }

            // verify all members are equivalent
            for (int ordinal = 0; ordinal < this.Members.Count; ordinal++)
            {
                EdmMember thisMember  = this.Members[ordinal];
                EdmMember otherMember = other.Members[ordinal];

                // if members are different, return false
                if (!thisMember.EdmEquals(otherMember) ||
                    !thisMember.TypeUsage.EdmEquals(otherMember.TypeUsage))
                {
                    return(false);
                }
            }

            return(true);
        }
        //JsrSoft     private static void CalculatePropertyAccessibility(MetadataItem item,
        public static void CalculatePropertyAccessibility(MetadataItem item,
            out string propertyAccessibility,
            out string getterAccessibility,
            out string setterAccessibility)
        {
            getterAccessibility = GetAccessibility(item, GETTER_ACCESS);
            int getterRank = AccessibilityRankIdLookup[getterAccessibility];

            setterAccessibility = GetAccessibility(item, SETTER_ACCESS);
            int setterRank = AccessibilityRankIdLookup[setterAccessibility];

            int propertyRank = Math.Max(getterRank, setterRank);
            if (setterRank == propertyRank)
            {
                setterAccessibility = String.Empty;
            }

            if (getterRank == propertyRank)
            {
                getterAccessibility = String.Empty;
            }

            propertyAccessibility = AccessibilityRankIdLookup.Where(v => v.Value == propertyRank).Select(v => v.Key).Single();
        }
 private static void AddOtherContent(Som.SchemaElement element, MetadataItem item)
 {
     if (element.OtherContent.Count > 0)
     {
         item.AddMetadataProperties(element.OtherContent);
     }
 }
Beispiel #12
0
 internal static void AssertItemHasIdentity(MetadataItem item, string argumentName)
 {
     Debug.Assert(!string.IsNullOrEmpty(item.Identity), "Item has empty identity.");
     EntityUtil.GenericCheckArgumentNull(item, argumentName);
 }
        /// <summary>
        /// Inheritors would override this method to supply custom documetation for the entire document.
        /// </summary>
        /// <param name="item">A <see cref="MetadataItem"/> object representing the object the documentation is being written for.</param>
        /// <returns>The desired documentation.</returns>
        protected virtual string WriteDocumentation(MetadataItem item)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine("/*", TabQueue);
            builder.AppendLine(string.Format(" * Generated on {0} with {1}", DateTime.Now.ToLongDateString(), this.GetType().FullName), TabQueue);
            builder.AppendLine(string.Format(" * Generated by {0}", WindowsIdentity.GetCurrent().Name), TabQueue);
            builder.AppendLine(" */", TabQueue);

            return builder.ToString();
        }
 /// <summary>
 /// Given an item, returns an instance of the item attribute described by this class.
 /// </summary>
 /// <param name="item">Item from which to retrieve attribute.</param>
 /// <returns>Item attribute.</returns>
 internal MetadataProperty GetMetadataProperty(MetadataItem item)
 {
     return(new MetadataProperty(_propertyInfo.Name, _attribute.Type, _attribute.IsCollectionType,
                                 new MetadataPropertyValue(_propertyInfo, item)));
 }
        /// <summary>
        /// Validate an item object
        /// </summary>
        /// <param name="item">The item to validate</param>
        /// <param name="errors">An error collection for adding validation errors</param>
        /// <param name="validatedItems">A dictionary keeping track of items that have been validated</param>
        private void InternalValidate(MetadataItem item, List <EdmItemError> errors, HashSet <MetadataItem> validatedItems)
        {
            Debug.Assert(item != null, "InternalValidate is called with a null item, the caller should check for null first");

            // If the item has already been validated or we need to skip readonly items, then skip
            if ((item.IsReadOnly && SkipReadOnlyItems) || validatedItems.Contains(item))
            {
                return;
            }

            // Add this item to the dictionary so we won't validate this again.  Note that we only do this
            // in this function because every other function should eventually delegate to here
            validatedItems.Add(item);

            // Check to make sure the item has an identity
            if (string.IsNullOrEmpty(item.Identity))
            {
                AddError(errors, new EdmItemError(System.Data.Entity.Strings.Validator_EmptyIdentity, item));
            }

            switch (item.BuiltInTypeKind)
            {
            case BuiltInTypeKind.CollectionType:
                ValidateCollectionType((CollectionType)item, errors, validatedItems);
                break;

            case BuiltInTypeKind.ComplexType:
                ValidateComplexType((ComplexType)item, errors, validatedItems);
                break;

            case BuiltInTypeKind.EntityType:
                ValidateEntityType((EntityType)item, errors, validatedItems);
                break;

            case BuiltInTypeKind.Facet:
                ValidateFacet((Facet)item, errors, validatedItems);
                break;

            case BuiltInTypeKind.MetadataProperty:
                ValidateMetadataProperty((MetadataProperty)item, errors, validatedItems);
                break;

            case BuiltInTypeKind.NavigationProperty:
                ValidateNavigationProperty((NavigationProperty)item, errors, validatedItems);
                break;

            case BuiltInTypeKind.PrimitiveType:
                ValidatePrimitiveType((PrimitiveType)item, errors, validatedItems);
                break;

            case BuiltInTypeKind.EdmProperty:
                ValidateEdmProperty((EdmProperty)item, errors, validatedItems);
                break;

            case BuiltInTypeKind.RefType:
                ValidateRefType((RefType)item, errors, validatedItems);
                break;

            case BuiltInTypeKind.TypeUsage:
                ValidateTypeUsage((TypeUsage)item, errors, validatedItems);
                break;

            // Abstract classes
            case BuiltInTypeKind.EntityTypeBase:
            case BuiltInTypeKind.EdmType:
            case BuiltInTypeKind.MetadataItem:
            case BuiltInTypeKind.EdmMember:
            case BuiltInTypeKind.RelationshipEndMember:
            case BuiltInTypeKind.RelationshipType:
            case BuiltInTypeKind.SimpleType:
            case BuiltInTypeKind.StructuralType:
                Debug.Assert(false, "An instance with a built in type kind refering to the abstract type " + item.BuiltInTypeKind + " is encountered");
                break;

            default:
                //Debug.Assert(false, String.Format(CultureInfo.InvariantCulture, "Validate not implemented for {0}", item.BuiltInTypeKind));
                break;
            }

            // Performs other custom validation
            IEnumerable <EdmItemError> customErrors = CustomValidate(item);

            if (customErrors != null)
            {
                errors.AddRange(customErrors);
            }
        }
 /// <summary>
 /// Inheritors would override this method to supply custom documentation for a given method.
 /// </summary>
 /// <param name="item">A <see cref="MetadataItem"/> object representing the object the documentation is being written for.</param>
 /// <returns>The desired documentation.</returns>
 protected virtual string WriteDocumentationMethod(MetadataItem item)
 {
     return string.Empty;
 }
Beispiel #17
0
 /// <summary>
 /// Returns all facet descriptions associated with this type.
 /// </summary>
 /// <returns>Descriptions for all built-in facets for this type.</returns>
 internal virtual IEnumerable <FacetDescription> GetAssociatedFacetDescriptions()
 {
     return(MetadataItem.GetGeneralFacetDescriptions());
 }
 /// <summary>
 /// Just checks for identities to be equal
 /// </summary>
 /// <param name="item"></param>
 /// <returns></returns>
 internal virtual bool EdmEquals(MetadataItem item)
 {
     return ((null != item) &&
             ((this == item) || // same reference
              (BuiltInTypeKind == item.BuiltInTypeKind &&
               Identity == item.Identity)));
 }
 protected PropertyEmitterBase(ClientApiGenerator generator, MetadataItem item, bool declaringTypeUsesStandardBaseType)
     : base(generator, item)
 {
     Debug.Assert(item != null, "item is null");
     _declaringTypeUsesStandardBaseType = declaringTypeUsesStandardBaseType;
 }
Beispiel #20
0
 private static Documentation GetDocumentation(MetadataItem item)
 {
     if (item is Documentation)
         return (Documentation)item;
     else
         return item.Documentation;
 }
        /// <summary>
        /// Inheritors would override this method to supply custom documentation for a given type.
        /// </summary>
        /// <param name="item">A <see cref="MetadataItem"/> object representing the object the documentation is being written for.</param>
        /// <returns>The desired documentation.</returns>
        protected virtual string WriteDocumentationType(MetadataItem item)
        {
            StringBuilder builder = new StringBuilder();

            if (item.Documentation != null)
            {
                builder.AppendLine("/// <summary>", TabQueue);
                builder.AppendLine(string.Format("/// {0}", item.Documentation.Summary), TabQueue);
                if (!string.IsNullOrWhiteSpace(item.Documentation.LongDescription))
                    builder.AppendLine(string.Format("/// {0}", item.Documentation.LongDescription), TabQueue);
                builder.AppendLine("/// </summary>", TabQueue);
            }

            return builder.ToString();
        }
Beispiel #22
0
        /// <summary>
        /// EdmEquals override verifying the equivalence of all members and their type usages.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        internal override bool EdmEquals(MetadataItem item)
        {
            // short-circuit if this and other are reference equivalent
            if (Object.ReferenceEquals(this, item)) { return true; }

            // check type of item
            if (null == item || BuiltInTypeKind.RowType != item.BuiltInTypeKind) { return false; }
            RowType other = (RowType)item;

            // check each row type has the same number of members
            if (this.Members.Count != other.Members.Count) { return false; }

            // verify all members are equivalent
            for (int ordinal = 0; ordinal < this.Members.Count; ordinal++)
            {
                EdmMember thisMember = this.Members[ordinal];
                EdmMember otherMember = other.Members[ordinal];

                // if members are different, return false
                if (!thisMember.EdmEquals(otherMember) ||
                    !thisMember.TypeUsage.EdmEquals(otherMember.TypeUsage))
                {
                    return false;
                }
            }

            return true;
        }
 private static MemberAttributes GetAccessibilityValue(MetadataItem item, string attribute)
 {
     MemberAttributes accessibilty = MemberAttributes.Public;
     MetadataProperty metadataProperty;
     if (item.MetadataProperties.TryGetValue(Utils.GetFullyQualifiedCodeGenerationAttributeName(attribute), false, out metadataProperty))
     {
         accessibilty = GetCodeAccessibilityMemberAttribute(metadataProperty.Value.ToString());
     }
     return accessibilty;
 }
 /// <summary>
 /// Construct the EdmItemError with an error message
 /// </summary>
 /// <param name="message">The error message for this validation error</param>
 /// <param name="item">The item that causes the validation error</param>
 public EdmItemError(string message, MetadataItem item)
     : base(message)
 {
     _item = item;
 }
 /// <summary>
 /// Allows derived classes to perform additional validation
 /// </summary>
 /// <param name="item">The item to perform additional validation</param>
 /// <returns>A collection of errors</returns>
 protected virtual IEnumerable <EdmItemError> CustomValidate(MetadataItem item)
 {
     return(null);
 }
        /// <summary>
        /// Override EdmEquals to support value comparison of TypeUsage property
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        internal override bool EdmEquals(MetadataItem item)
        {
            // short-circuit if this and other are reference equivalent
            if (Object.ReferenceEquals(this, item)) { return true; }

            // check type of item
            if (null == item || BuiltInTypeKind.CollectionType != item.BuiltInTypeKind) { return false; }
            CollectionType other = (CollectionType)item;

            // compare type usage
            return this.TypeUsage.EdmEquals(other.TypeUsage);
        }
        private static string GetAccessibility(MetadataItem item, string name)
        {
            string accessibility;
            if (MetadataTools.TryGetStringMetadataPropertySetting(item, name, out accessibility))
            {
                return TranslateUserAccessibilityToCSharpAccessibility(accessibility);
            }

            return "public";
        }
 public ODataUriItem(MetadataItem item_, UriType uriType_)
 {
     this.Item = item_;
     this.uriType = uriType_;
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="generator"></param>
 /// <param name="schemaType"></param>
 protected SchemaTypeEmitter(ClientApiGenerator generator, MetadataItem item)
 : base(generator, item)
 {
 }
 protected static TypeAttributes GetTypeAccessibilityValue(MetadataItem item)
 {
     TypeAttributes accessibilty = TypeAttributes.Public;
     MetadataProperty metadataProperty;
     if (item.MetadataProperties.TryGetValue(Utils.GetFullyQualifiedCodeGenerationAttributeName(XmlConstants.TypeAccess), false, out metadataProperty))
     {
         accessibilty = GetCodeAccessibilityTypeAttribute(metadataProperty.Value.ToString());
     }
     return accessibilty;
 }
        /// <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();
            }
        }
 protected MetadataItemEmitter(ClientApiGenerator generator, MetadataItem item)
     :base(generator)
 {
     Debug.Assert(item != null, "item is null");
     _item = item;
 }
 /// <summary>
 /// Construct the EdmItemError with an error message
 /// </summary>
 /// <param name="message">The error message for this validation error</param>
 /// <param name="item">The item that causes the validation error</param>
 public EdmItemError(string message, MetadataItem item)
     : base(message)
 {
     _item = item;
 }
 /// <summary>
 /// Constructor taking item.
 /// </summary>
 /// <param name="item">Item with which the collection is associated.</param>
 internal MetadataPropertyCollection(MetadataItem item)
     : base(GetSystemMetadataProperties(item))
 {
 }
Beispiel #35
0
 /// <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)
 {
 }